FZU 2147(数学,规律)

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

Submit  Back  Status  Discuss

题意:输入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;
}                   
时间: 2024-08-29 16:25:58

FZU 2147(数学,规律)的相关文章

[C++]LeetCode: 114 Permutation Sequence(返回第k个阶乘序列——寻找数学规律)

题目: The set [1,2,3,-,n] contains a total of n! unique permutations. By listing and labeling all of the permutations in order, We get the following sequence (ie, for n = 3): "123" "132" "213" "231" "312" &q

HDU 1005 Number Sequence (数学规律)

Number Sequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 104190    Accepted Submission(s): 25232 Problem Description A number sequence is defined as follows: f(1) = 1, f(2) = 1, f(n) = (A

Uva 1315 - Creaz tea party ( 数学 + 规律 )

Uva 1315 - Creaz tea party (  数学 + 规律 ) 题意: 一个环,围在一个坐了N个人.每次操纵可以交换相邻的两个人的位置.求最少需要交换几次,可以变为逆序. 这里的逆序指的是原来在A左边的人在A的右边,在A右边的在A的左边. 分析: 如果是线性的,,,果断类似冒牌排序(n)(n-1)/2 但是这里是环,推了推但是推不出结果..结论是将环分为两段线性的序列,线性的满足上面的公式. 如:     1 2 3 4 5  线性:  5 4 3 2 1  ( 10次 ) 环状

【算法学习笔记】73.数学规律题 SJTU OJ 1058 小M的机器人

Description 小M有很多个机器人,他们要么一直说真话,要么一直说假话. 然后每个人都说: (1). 不到N个人比我工作得多 (2). 至少M个人的工资比我高. 保证没有两个人的工作一样重,也没有两个人的工资一样高,问至少有多少机器人? Input Format 一行两个数整数N, M (  1≤N,M < 2^31) Output Format 一个整数K表示至少有K个人 Hint 想不出来的同学... 不要想得太复杂了... Sample Input 2 2 Sample Outpu

自己发现的数学规律一

数学规律一 %是取余数运算 123 % 9 = 6 (1+2+3) % 9 = 6 3456795 % 9 = 3 (3+4+5+6+7+9+5) % 9 = 3 (-123) % 9= 3 [-(1+2+3)] % 9 = 3 将被除数记作A1A2A3...An,除数为9,余数记作q. 则有: A1A2A3...An % 9 = q1 (A1+A2+A3+...+An) % 9 = q2 (-A1A2A3...An) % 9 = q3 [-(A1+A2+A3+...+An)] % 9 = q4

hihoCoder 1584 Bounce 【数学规律】 (ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛)

#1584 : Bounce 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 For Argo, it is very interesting watching a circle bouncing in a rectangle. As shown in the figure below, the rectangle is divided into N×M grids, and the circle fits exactly one grid. The bouncing

UVA10940 Throwing cards away II【数学规律+约瑟夫环】

Given is an ordered deck of n cards numbered 1 to n with card 1 at the top and card n at the bottom. The following operation is performed as long as there are at least two cards in the deck: Throw away the top card and move the card that is now on th

PAT甲级——1104 Sum of Number Segments (数学规律、自动转型)

本文同步发布在CSDN:https://blog.csdn.net/weixin_44385565/article/details/90486252 1104 Sum of Number Segments (20 分) Given a sequence of positive numbers, a segment is defined to be a consecutive subsequence. For example, given the sequence { 0.1, 0.2, 0.3,

FZU - 2147 A-B Game(找规律)

A-B Game Time Limit: 1000MS   Memory Limit: 32768KB   64bit IO Format: %I64d & %I64u Submit Status 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 p