Task DescriptionDiscussion (0)
Task :: z-first-grade
In the case you didn't know, Mr. Little Z was born, and grew up in Magic Land. His first job was to make Magic Ropes of any given length. In his office he has unlimited supply of one inch ropes. He also had two machines that can do the following things:
- The first machine works only during the day, and from a given rope of any length L (1 <= L <= N), it can extend the rope K times, as long as the length of the newly created rope is in the interval [1, N ].
- The second machine works only during the night, and from two given ropes L1 and L2 with the lengths in the interval [1, N ], it can produce ropes of the length L1 + L_2 and L1 - L_2, as long as the length of the newly created rope is in the interval [1, N ].
The second machine is kind of old, so when it produces a rope, the rope gets really hot, and it can not be used for producing new ropes on the same night.
- The first machine works only during the day, and from a given rope of any length L (1 <= L <= N), it can extend the rope K times, as long as the length of the newly created rope is in the interval [1, N ].
- The second machine works only during the night, and from two given ropes L1 and L2 with the lengths in the interval [1, N ], it can produce ropes of the length L1 + L_2 and L1 - L_2, as long as the length of the newly created rope is in the interval [1, N ].
The second machine is kind of old, so when it produces a rope, the rope gets really hot, and it can not be used for producing new ropes on the same night.
For given K and N, making a rope of some length requires certain number of days. For example, for K = 2 and N = 11, in order to make a rope of length 11 Mr. Little Z needs three days. He starts with three one-inch long ropes. On the fist day, he extends the first rope twice (each time by a factor of 2), and extends the second rope three times (each time by factor 2). So before the first night he has ropes of length 1, 4, and 8. Now the first night he makes a rope of length 3 (from ropes with lengths 4 and 1), now the second day he does not have to do anything. Finally the second night he makes the rope of lenght 11 (which is 8+3).
Let's now carefully examine the case when K = 3 and N = 10. On the first day, Little Z can make to following ropes:
- Length of 1
- Length of 3 = 1 * 3
- Length of 9 = 1 * 3 * 3
Now, after the second night (this is already day two!) he can have the following ropes:
- Length of 2 = 1 + 1 or 3 - 1
- Length of 4 = 3 + 1
- Length of 6 = 9 - 3
- Length of 8 = 9 - 1
During the second day he can now get new length by extending some length K times.
Finally, after the second night (this is the third day he can have the following ropes)
- Length of 5 = 3 + 2;
- Length of 7 = 6 + 1;
- Length of 1
- Length of 3 = 1 * 3
- Length of 9 = 1 * 3 * 3
Now, after the second night (this is already day two!) he can have the following ropes:
- Length of 2 = 1 + 1 or 3 - 1
- Length of 4 = 3 + 1
- Length of 6 = 9 - 3
- Length of 8 = 9 - 1
During the second day he can now get new length by extending some length K times.
Finally, after the second night (this is the third day he can have the following ropes)
- Length of 5 = 3 + 2;
- Length of 7 = 6 + 1;
INPUT:
You should read the data from the standard input. The first line will contain two integers K and N, where 1 <= K, N <= 1000000
You should read the data from the standard input. The first line will contain two integers K and N, where 1 <= K, N <= 1000000
OUTPUT:
To the standard output you should output N lines. The i-th line should contain one integer that represents the minimal number of days that Mr. Little Z needs to create a Magic Rope of length i.
To the standard output you should output N lines. The i-th line should contain one integer that represents the minimal number of days that Mr. Little Z needs to create a Magic Rope of length i.
Input:
Output:
This is the example from the text above
3 10
Output:
1
2
1
2
3
2
3
2
1
2
2
1
2
3
2
3
2
1
2
This is the example from the text above
Input:
Output:
In one day, Mr Little Z can make the ropes of length: 1, 2 (= 1 * 2), 4 (= 1 * 2 * 2), 8 (= 1 * 2^3) and 16 (= 1 * 2^4).
In two days Mr Little Z can make the following ropes: 3 (= 1 + 2), 5 (= 4 + 1), 6 (= 4 + 2), 7 (= 8 - 1), 9 (= 8 + 1), 10 (= 8 + 2), 12 (= 8 + 4), 14 (= 16 - 2), 15 (= 16 - 1).
Finally on the third day Mr Little Z can make ropes ready: 11 (= 8 + 3) and 13 (8 + 5)
2 16
Output:
1
1
2
1
2
2
2
1
2
2
3
2
3
2
2
1
1
2
1
2
2
2
1
2
2
3
2
3
2
2
1
In one day, Mr Little Z can make the ropes of length: 1, 2 (= 1 * 2), 4 (= 1 * 2 * 2), 8 (= 1 * 2^3) and 16 (= 1 * 2^4).
In two days Mr Little Z can make the following ropes: 3 (= 1 + 2), 5 (= 4 + 1), 6 (= 4 + 2), 7 (= 8 - 1), 9 (= 8 + 1), 10 (= 8 + 2), 12 (= 8 + 4), 14 (= 16 - 2), 15 (= 16 - 1).
Finally on the third day Mr Little Z can make ropes ready: 11 (= 8 + 3) and 13 (8 + 5)
Submit Solution
Available Languages
Task info
| Name: | z-first-grade |
| Time: | 5 sec. |
| Memory: | 64 MB |
| #Tests: | 50 |
| Author: | z |
| AddedBy: | admin |
Task Ratings
| Difficulty: | 5 (12 votes) |
| Quality: | 5 (10 votes) |
Acceptance Rate
Recent Submissions
Fastest Solutions
| User | Time |
|---|---|
| halil | 7.245 s. |
| oduleodule | 7.83 s. |
| Hachiikung | 14.1 s. |
| thepsint | 14.22 s. |
| neal_wu | 18.09 s. |
Solved By
Home
Training
Competitions
Forum
FAQ