Problem 2147 A-B Game

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

2
5 3
10086 110

 Sample Output

Case 1: 1
Case 2: 7
    

规律很好找,求多少次A-(A%X)<=B;也就是求A%X的最大值,这样减的次数才会尽可能少,于是枚举了几组数据,发现当X=A/2+1时,A%X最接近A;于是规律出来了;

#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
//const int N=101;
//char a[N][N];
int main()
{
int t,i;
long long a,b,x;
scanf("%d",&t);
int t1=t;
while(t--)
{
x=i=0;
scanf("%I64d%I64d",&a,&b);
while(a>b)
{
i++;
x=a/2+1;//关键找到这个规律;
a-=a%x;
}
printf("Case %d: ",t1-t);
printf("%d\n",i);
}
return 0;
}

FZU-2147-2147 A-B Game,规律题。。的更多相关文章

  1. LightOJ1010---Knights in Chessboard (规律题)

    Given an m x n chessboard where you want to place chess knights. You have to find the number of maxi ...

  2. Codeforces - 规律题 [占坑]

    发现自己容易被卡水题,需要强行苟一下规律题 CF上并没有对应的tag,所以本题集大部分对应百毒搜索按顺序刷 本题集侧重于找规律的过程(不然做这些垃圾题有什么用) Codeforces - 1008C ...

  3. ACM_送气球(规律题)

    送气球 Time Limit: 2000/1000ms (Java/Others) Problem Description: 为了奖励近段时间辛苦刷题的ACMer,会长决定给正在机房刷题的他们送气球. ...

  4. hdoj--1005--Number Sequence(规律题)

    Number Sequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  5. HDU 2147 kiki's game(博弈经典题)

    题目传送:http://acm.hdu.edu.cn/showproblem.php?pid=2147 Problem Description Recently kiki has nothing to ...

  6. FZU - 2037 -Maximum Value Problem(规律题)

    Let’s start with a very classical problem. Given an array a[1…n] of positive numbers, if the value o ...

  7. 洛谷 P1876 开灯(思维,枚举,规律题)

    P1876 开灯 题目背景 该题的题目是不是感到很眼熟呢? 事实上,如果你懂的方法,该题的代码简直不能再短. 但是如果你不懂得呢?那...(自己去想) 题目描述 首先所有的灯都是关的(注意是关!),编 ...

  8. Codeforces 959E. Mahmoud and Ehab and the xor-MST 思路:找规律题,时间复杂度O(log(n))

    题目: 解题思路 这题就是0,1,2...n-1总共n个数字形成的最小生成树. 我们可以发现,一个数字k与比它小的数字形成的异或值,一定可以取到k与所有正整数形成的异或值的最小值. 要计算n个数字的情 ...

  9. Visible Lattice Points(规律题)【数学规律】

    Visible Lattice Points 题目链接(点击) Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9031   ...

随机推荐

  1. 维骨力Glucosamine的最关键的几点...

    1.每日劑量應為多少?長期服用安全嗎? 由於葡萄糖胺(Glucosamine)和軟骨素(Chondroitin)原來就存在於人體,是人體每天會生產製造的必需營養素,因此,一般認為服用此類產品的安全性相 ...

  2. Excel 宏练习

    任务描述: 利用 Excel 绘制函数图像 f(x)=x^2/3+0.9*(3.3-x^2)^1/2*sin(a*x),并通过按钮事件来刷新图像. 问题分析: 可以参考类似 Matlab 绘图的方式, ...

  3. RHEL6.5---LVS(IP-TUN)

    实验环境: 主机名 IP  所需软件 master eth0==>192.168.30.160(RIP) eth0:1==>192.168.30.130(VIP) ipvsadm node ...

  4. java的学习方向

    在我身边有很多初学者,或者想入门的门外汉问我该如何的去学习一门新的技术,如果你是一窍不通的门外汉,我给你的建议是,报一个可靠的基础培训班.当然培训班的方向也分为很多,有前端的培训课程.有java的培训 ...

  5. Spring-bean(零)

    内容提要:红为1,黄2,绿3 -----配置形式:基于xml文件的方式:基于注解的方式 -----Bean的配置方式:通过全类名(反射),通过工厂方法(静态工厂方法&实例工厂方法),Facto ...

  6. struct和union

    struct的小秘密 C语言中的struct可以看做变量的集合,struct的问题: 空结构体占用多大内存? 例子1:空结构体的大小 #include<stdio.h> struct ST ...

  7. 用JS检测页面加载的不同阶段状态

    这可以通过用document.onreadystatechange的方法来监听状态改变, 然后用document.readyState == “complete”判断是否加载完成. 可以采用2个div ...

  8. 封装addClass 、 removeClass

    <script> window.onload = function() { var oDiv = document.getElementById('div1'); var oDiv2 = ...

  9. 最短路 || POJ 2387 Til the Cows Come Home

    从点N到1的最短路 *记得无向图两个方向都要建边就好了…… 以及多组数据= = #include <iostream> #include <cstdio> #include & ...

  10. 欧拉函数 || LightOJ 1370 Bi-shoe and Phi-shoe

    给出x,求最小的y使y的欧拉函数大于等于x *解法:i).求出1e6之内的数的欧拉函数,遍历找             ii).求比x大的第一个质数——因为每个质数n的欧拉函数都是n-1 wa一次是因 ...