Log inSign up
Problems / B044

Choosing scale weights

200 ptsCases 15Set by dongbinna
Added October 30.
1 solved1 attempted1 submissionssolvers took 1.0 tries on average

Statement

A workshop has one balance scale with two pans, and it has many weights. The weights grow by a fixed rule. The first weight is 1 and the second is 2, and from the third one on, each weight is the sum of the two weights right before it. The weights therefore run 1, 2, 3, 5, 8, 13, 21, 34, 55, 89 and so on. There is only one weight of each size, so a weight that has already been placed cannot be placed again.

When a customer names a weight, the owner of the workshop places weights on one pan to match that weight exactly. The weights placed have to add up to the weight the customer named. The number of weights placed should be as small as possible.

Several customers can be served at once. Write a program that, given the number of customers T and one named weight for each customer, finds for each customer the weights that match that weight with the fewest pieces, listed from the smallest. There are weights heavier than 1,000,000,000 as well, so any weight can always be matched.

For example, suppose a customer names the weight 100. The heaviest weight that is at most 100 is 89. Placing 89 leaves 11, and the heaviest weight that is at most 11 is 8. Placing 8 leaves 3, and since there is a weight of 3, placing it leaves nothing. Writing out this process gives the following table.

StepWeight leftWeight placed
110089
2118
333
40none

Three weights were placed, 3 and 8 and 89, and the three add up to 100. Written from the smallest they are 3, 8, 89, so in this example the answer for this customer is those three numbers. There is no way to match 100 with two weights or fewer.

If another customer names the weight 12, placing 8 leaves 4, placing 3, the heaviest weight that is at most 4, leaves 1, and placing the weight of 1 finishes it. The answer in that case is 1, 3, 8.

Input and Output Examples

Example 1

Input

2
100
1000000000

Output

3 8 89
1 5 13 89 233 1597 28657 75025 196418 514229 5702887 24157817 267914296 701408733

Example 2

Input

1
325631899

Output

1 3 8 21 89 233 610 1597 4181 46368 121393 3524578 14930352 39088169 267914296

Example 3

Input

1
150128012

Output

5 55 144 610 2584 6765 28657 75025 196418 514229 2178309 5702887 39088169 102334155

Input

  • The number of customers T is given first, on the first line. T is a natural number from 1 to 20.

  • From the second line through line T+1, the weight each customer named is given, one per line. Each weight is a natural number from 1 to 1,000,000,000. One number comes per line, so the input is T+1 lines in all.

  • The weights themselves are not given in the input. You build them yourself with the rule that starts at 1 and 2 and grows by adding the two weights right before.

Output

  • Print one line per customer, giving the weights to place from the smallest, in the order the customers are given in the input.

  • After writing one customer's answer, print a newline. Do not add a further blank line after the last line.

  • Grading compares the output with the expected value down to the last character. When a line holds more than one value, the values are separated by a single space.

Requirements

  • Read the input from standard input and write the answer to standard output
  • The weights start at 1 and 2 and grow by adding the two weights right before. There is only one weight of each size, so it cannot be placed twice
  • The weights placed have to add up exactly to the weight the customer named, and among the ways of doing that the number of weights has to be the smallest
  • Print one line per customer, from the smallest weight, and the order of the lines matches the order given in the input
  • Grading compares the output with the expected value down to the last character
  • You must write a program that reads from standard input and writes to standard output
  • Trailing spaces at the end of a line and blank lines at the end of the output are ignored when grading
  • The languages you can use are Python and JavaScript
  • The memory limit is 256MB. The browser does not measure it, it only states it
  • The time limit is set by measuring the setter's reference solution on the same runtime
  • On this problem you submit code, not a prompt. That code runs in the browser on this device, and all that goes to the server is a fingerprint of the output and the time it took. Whether it is correct is decided by the server. The run time is a number each device reports, so the code and the device details are posted next to it on the leaderboard.
  • There are 15 cases, and 3 of them show the input together with the expected output. The rest are used only when you submit and are not shown on this page.
  • You have to pass all 15 cases to solve this.
Read the requirements carefully before solving. Tampering with the grading to make a submission look like a pass can get you sanctioned if caught. The code you submit is published on the leaderboard along with the result.

Examples

3 public cases. Judging also uses hidden cases. You have to pass all 15 cases to solve this.

Input
Expected output
2
100
1000000000
3 8 89
1 5 13 89 233 1597 28657 75025 196418 514229 5702887 24157817 267914296 701408733
1
325631899
1 3 8 21 89 233 610 1597 4181 46368 121393 3524578 14930352 39088169 267914296
1
150128012
5 55 144 610 2584 6765 28657 75025 196418 514229 2178309 5702887 39088169 102334155

Solution

Your code runs on this device. Only the fingerprint of the output and the elapsed time go to the server. The server decides whether it is correct.

0 chars1 lineMemory 256MB (recorded only)Reference 2.0ms

Submitting requires you to log in. Running against the public cases works without one.

You can test with 3 public cases. Submitting runs the hidden cases too.

People who solved this problem

The time shown is the time spent solving. Input reading time is outside the solver's control, so it is excluded. And since each device reports this value itself, we record which device measured it.

1bampal240ms408 charsPythonWindows NT 10.0 / Chrome/156.0.0.0 / 8코어 / 16GB

Log in and you can see the code once you solve this problem.