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. solrJ的使用--覆盖创建索引,查询,删除索引【转自http://blog.sina.com.cn/s/blog_64ac3ab10100t3mq.html】

    package com.xzhe.common.search; import java.util.ArrayList; import java.util.Collection; import java ...

  2. SpringBoot 2.x (8):模板引擎

    SpringBoot中有很多的starter:本质是多个JAR包集合 比如我们常用的: <dependency> <groupId>org.springframework.bo ...

  3. 作用域链、this细说

    一.作用域链 作用域:浏览器给js的一个生存环境(栈内存) 作用域链:js中的关键字var和function 都可以提前声明和定义,提前声明和定义的放在我们的内存地址(堆内存)中.然后js从上到下逐行 ...

  4. B/S网络架构

    B/S基于统一的应用层协议HTTP来交互数据,目前的B/S网络架构大多采用如图所示的架构设计,既要满足海量用户访问请求,又要保持用户请求的快速响应. 当一个用户在浏览器输入www.taobao.com ...

  5. 6 Specialzed layers 特殊层 第二部分 读书笔记

    CAGradientLayer   CAGradientLayer is used to generate a smooth gradient between two or more colors. ...

  6. Junit测试集锦

    Junit测试集锦 前言: 一个程序从设计很好的状态开始,随着新的功能不断地加入,程序逐渐地失去了原有的结构,最终变成了一团乱麻.所以在开发过程中,对于程序员来说,测试是非常重要的.言归正传,开始Ju ...

  7. UVA 11346 Probability 概率 (连续概率)

    题意:给出a和b,表示在直角坐标系上的x=[-a,a] 和 y=[-b,b]的这样一块矩形区域.给出一个数s,问在矩形内随机选择一个点p=(x,y),则(0.0)和p点组成的矩形面积大于s的概率是多少 ...

  8. 洛谷 P1618 三连击(升级版)

    题目描述 将1,2,…,9共9个数分成三组,分别组成三个三位数,且使这三个三位数的比例是A:B:C,试求出所有满足条件的三个三位数,若无解,输出“No!!!”. //感谢黄小U饮品完善题意 输入输出格 ...

  9. Elasticsearch插件清单

    1.API插件:主要对Elasticsearch添加的API特性或者功能,通常用于搜索或者映射 2. 报警插件: 当Elasticsearch的索引指标超过阀值时就会触发 3. 分词插件:ik是比较好 ...

  10. 暑假集训 || 概率DP

    Codeforces 148D 考虑状态转移..https://www.cnblogs.com/kuangbin/archive/2012/10/04/2711184.html题意:原来袋子里有w只白 ...