码迷,mamicode.com
首页 > 其他好文 > 详细

FZU 2147(数学,规律)

时间:2016-05-07 10:36:39      阅读:179      评论:0      收藏:0      [点我收藏+]

标签:

Problem 2147 A-B Game

Accept: 1202    Submit: 2853
Time Limit: 1000 mSec    Memory Limit : 32768 KB

技术分享 Problem 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: 1
Case 2: 7




题意:输入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;
}                   



FZU 2147(数学,规律)

标签:

原文地址:http://blog.csdn.net/qq_24489717/article/details/51331806

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!