Input Fat brother and Maze are playing a kind of special (hentai) game by two integers A and B. First Fat brother write an integer A on a white paper and then Maze start to change this integer. Every time M
aze can select an integer x between 1 and A-1 then change A into A-(A%x). The game ends when this integer is less than or equals to B. Here is the problem, at least how many times Maze needs to perform to end this special (hentai) game.Output The first line of the date is an integer T, which is the number of the text cases.
Then T cases follow, each case contains two integers A and B described above.
1 <= T <=100, 2 <= B < A < 100861008610086
Sample Input For each case, output the case number first, and then output an integer describes the number of times Maze needs to perform. See the sample input and output for more details.
Sample Output 2 5 3 10086 110 Case 1: 1 Case 2: 7
题解:
贪心,每次取X最大,那么什么时候X最大,当X = A / 2 + 1的时候,因为A/2的话,偶数就GG了,然后就能保证每次A减去的就是最大的,剩下的A就是A/2 + 1
#include <cstdio> #include <cstring> #include <iostream> using namespace std; #define CLR(x , v) memset(x , v , sizeof(x)) #define CASE(x) printf("Case %d: " , x) typedef unsigned long long LL; int t; LL a , b; int main() { scanf("%d" , &t); for(int c = 1 ; c <= t ; ++c) { LL ans = 0; scanf("%lld%lld" , &a , &b); while(a > b) { a = a >> 1 | 1; ++ans; } CASE(c); printf("%d\n" , ans); } }