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. nginx中常见的变量

    $arg_PARAMETER        客户端GET请求PARAMETER的值. $args     请求中的参数. $binary_remote_addr 二进制码形式的客户端地址. $body ...

  2. Visual Studio Code配置 HTML 开发环境

    Visual Studio Code配置 HTML 开发环境 https://v.qq.com/x/page/l0532svf47c.html?spm=a2h0k.11417342.searchres ...

  3. AS 开发环境配置

    安装时不用设置代理(proxy). 建议选择标准安装,自定义安装容易选掉一些功能.插件. SDK Tools里的(HAXM installer)有时会未安装,安装完需检查(HAXM installer ...

  4. poj2385 Apple Catching

    思路: 简单dp. 实现: #include <iostream> #include <cstdio> #include <cstring> using names ...

  5. 一份最贴近真实面试的Java基础面试题

    这是一份Java基础知识的面试题.在网上的关于Java的面试题数不胜数,但认真看过感觉大多数都没有实用性,有很多是面试官根本就不会问到的,那些已经脱离了实际开发的技术问题.而这份资料来源自一份个人觉得 ...

  6. ICEcoder显示汉字出现乱码的处理

    在网上看到icecoder这个小东西,是一个基于web的编辑器,很不错.唯一的缺点是打开的文件中汉字会变成乱码. 经查看源代码,在lib/file-control.php中,第89行是: echo ' ...

  7. Window服务程序(windows service application)如何调试

    服务程序不能通过常规的按F5或F11的方式来进行调试和运行,也无法立即运行一个服务或逐步调试它的代码. 因此,你必须安装并启动你的服务,然后附属(attach)一个Debugger到这个服务的进程上.

  8. java分段加载数据,循环和递归两种方式

    package org.jimmy.autosearch2019.test; import java.util.ArrayList; public class Test20190328 { priva ...

  9. JavaSE-30 BigDecimal类的使用

    问题 Java(其他编程语言也存在类似问题)中浮点数直接进行算术运算会导致精度丢失. 示例代码: System.out.println("1.0 - 0.9 =" + (1.0 - ...

  10. mysql 报错:ERROR 1418 (HY000): This function has none of DETERMINISTIC, NO SQL, or READS SQL DATA

    解决办法:设置临时环境变量 ;