- Mã:
- Phuc1
- Tên:
- Up and Down
- Dạng thi:
- oi
- Thang điểm:
- 10 điểm
- Giới hạn thời gian:
- 1 giây
- Giới hạn bộ nhớ:
- 256 MB
- Nguồn bài tập:
- SCPC 2019
- Được tạo bởi:
- phucnq
Given an integer greater than or equal to , you are going to play a game where you repeat the “operation”, of which the rules are given below.
The rule below is for one operation.
You will run the operation on the resulting integer repeatedly.
As you can see in the rules, when the integer you have equals , no operation is performed and the game stops.
1. If the current integer is , no operation is performed and the game stops
2. If the current integer is an odd number other than , you add to it.
3. If the current integer is even, you divide it by .
For example, if you are initially given , and the game stops after operation.
If you are initially given , and the game stops after operations.
If you are initially given , and the game stops after operations.
If you are initially given , and the game stops after operations.
As you can see in the previous two examples, if you know the number of operations for , then you will immediately know the number of operations for .
You are to write a program that calculates the total number of operations for , given and ().
- Time Limit: 1 second for at most test cases. (if you program in Java, then you have 2 seconds).
If your program exceeds the time limit, then it is terminated immediately.
You can still obtain partial scores (0≤ your score< full score) in that case. If you program in C/C++, use “setbuf(stdout, NULL);” just once before your first call of printf.
If you don’t do this and your program exceeds the time limit, your score is 0 and you cannot obtain partial scores.
If you program in C++, use "setbuf(stdout, NULL);" as above and use “cout” instead of "printf" to obtain partial scores.
If you program in Java, use "System.out.printIn".
※ Check the provided sample code for details.
If you get partial score when your program runs within the time limit, it failed in some test cases.
- Memory Limit : heap, global, static 256MB, stack 100MB
- Allowed number of submissions: 10 (if two or more have the same score, the one with the fewer number of submissions gets higher rank.)
Memory Limit
stack : 100MB
Input
The first line has , the number of test cases.
Then cases are provided in the following lines. ()
The first line of each test case consists of two integers and . ()
- Scores : The maximum scores out of your submissions. (Full score: 100)
The group of test cases are as follows. When you report the right answers for all test cases in a group, you get its partial score.
ㆍ Group 1 (34 points) : .
ㆍ Group 2 (66 points) : No additional restrictions beyond the input specification.
Output
For the -th test case, “Case #C” should be printed out in the first line.
The following line should contain the total sum of number of operations for
Theme :
Mời bạn soạn code