FZU 2147 A-B Game(数学推导题)

来源:互联网 发布:linux可以做什么 编辑:程序博客网 时间:2024/06/05 08:37
H - A-B Game
Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u
Submit Status Practice FZU 2147

Description

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 Maze 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.

Input

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

Output

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 Input

25 310086 110

Sample Output

Case 1: 1Case 2: 7

题意:
不断按A-(A%x)的值改变A值,并且要大于B,问最少能操作几次,满足A<=B
思路:
我们通过发现可以得知,x从1向A-1,取得到的A%x的数是先增后减的,于是可以猜想x最好是选择去A/2,,然后我们发现如果A为偶数的话,A%(A/2)==0,所以我们只要A/2+1,就可以的到A%(x)的最大值,每一次都这么取,记录取了多少次

#include <queue>#include <cmath>#include <cstdio>#include <string>#include <cstring>#include <iostream>#include <algorithm>using namespace std;//#pragma comment(linker, "/STACK:1024000000,1024000000")#define FIN             freopen("input.txt","r",stdin)#define FOUT            freopen("output.txt","w",stdout)#define fst             first#define snd             secondtypedef __int64  LL;typedef pair<int, int> PII;const int MAXN = 100 + 5;int T;LL N, M;char G[MAXN][MAXN];int main() {#ifndef ONLINE_JUDGE    //FIN;//    FOUT;#endif // ONLINE_JUDGE    int cas = 0;    scanf ("%d", &T);    while (T --) {        scanf ("%I64d %I64d", &N, &M);        LL i = 0;        while(N > M){            LL k = N / 2 + 1;            N -= N % k;            i ++;        }        printf ("Case %d: %I64d\n", ++cas, i);    }    return 0;}


1 0