The bell and the drum
Statement
A craftsman in a workshop works from numbered job orders. An order number is an integer of 0 or more, and once the craftsman has an order in hand, the number tells him what to do.
1) On order 0 he strikes the bell once and that order is done.
2) On order 1 he strikes the drum once and that order is done.
3) On order K, where K is 2 or more, he first carries order K-1 through to the end as though he had been given it, and then carries order K-2 through to the end the same way. In this case the craftsman strikes neither the bell nor the drum himself.
The owner of the workshop wants to know how many times the bell rings and how many times the drum rings when order N is given once. The owner asks this T times.
So, given an order number N, write a program that finds the number of times the bell rings and the number of times the drum rings, in that order.
For example, suppose order N=3 is given once. Order 3 calls up order 2 and order 1 in turn, and order 2 among them calls up order 1 and order 0 in turn. Writing out the steps the craftsman goes through gives the following.
| Step | 1 | 2 | 3 | 4 | 5 |
|---|---|---|---|---|---|
| Order carried out | order 3 | order 2 | order 1 | order 0 | order 1 |
| What rang | drum | bell | drum |
The bell rang once and the drum rang twice. So the answer in this case is 1 and 2.
Counting the same way for order numbers from 0 up to 5 gives the following.
| N | 0 | 1 | 2 | 3 | 4 | 5 |
|---|---|---|---|---|---|---|
| Times the bell rang | 1 | 0 | 1 | 1 | 2 | 3 |
| Times the drum rang | 0 | 1 | 1 | 2 | 3 | 5 |
Order 0 and order 1 ring once on the spot and finish, so they give 1 and 0, and 0 and 1. Every number above them comes out as the counts of the two numbers just below it added together.
Input and Output Examples
Example 1
Input
3 0 1 3
Output
1 0 0 1 1 2
Example 2
Input
2 39 40
Output
39088169 63245986 63245986 102334155
Example 3
Input
1 0
Output
1 0
Input
First the number of times the owner asks T is given as a natural number. (T is a natural number less than or equal to 41.)
Then T lines follow, each holding one order number N given that time, one per line and in order. (N is an integer from 0 to 40.) Cases where N is 0 or 1 are given as well.
Output
Across T lines, print for each order the number of times the bell rang and the number of times the drum rang, in that order, on one line separated by a single space. Do not attach a space after the drum count, break the line there.
Requirements
- Order 0 rings only the bell once, and order 1 rings only the drum once
- An order of 2 or more strikes no bell and no drum itself, it calls up the two orders below it in turn
- If the same order number is called up several times, every one of those times is counted
- You have to count up to N=40, so you can build the counts up from the small numbers ahead of time and use them
- Print two numbers on one line separated by a single space, with the bell first
- 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.
- The output has to match the expected value down to the character. A space inside a line counts the same as any other character.
- 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.
Examples
3 public cases. Judging also uses hidden cases. You have to pass all 15 cases to solve this.
3 0 1 3
1 0 0 1 1 2
1 0
1 0
2 39 40
39088169 63245986 63245986 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.
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.
Log in and you can see the code once you solve this problem.