标签:
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.
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
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.
题意:输入A,B,从区间[1,A-1]中选择一个数字X,使得A=A-A%X;问至少需要几次才能使A<=B
题解:我们需要尽量使得A%X大,建议打个表找下规律,可以发现在A/2左右的三个数字可以得到最大的余数,那么直接模拟一下就好了
#include<cstdio> #include<cstring> #include<cstdlib> #include<cmath> #include<iostream> #include<algorithm> #include<vector> #include<map> #include<set> #include<queue> #include<string> #include<bitset> #include<utility> #include<functional> #include<iomanip> #include<sstream> #include<ctime> using namespace std; #define N int(1e2+50) #define inf int(0x3f3f3f3f) #define mod int(1e9+7) typedef long long LL; char c; int main() { #ifdef CDZSC freopen("i.txt", "r", stdin); //freopen("o.txt", "w", stdout); int _time_jc = clock(); #endif int t,sum,k = 1; LL n,m,x1,x2,x3; scanf("%d", &t); while (t--) { int ans=0; scanf("%I64d%I64d",&n,&m); while(n>m) { x2=n/2; x1=x2+1; x3=x2-1; n-=max(n%x2,max(n%x1,n%x3)); ans++; } printf("Case %d: %d\n",k++,ans); } return 0; }
标签:
原文地址:http://blog.csdn.net/qq_24489717/article/details/51331806