Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 9848    Accepted Submission(s): 5011

Problem Description
There is a hill with n holes around. The holes are signed from 0 to n-1.

A rabbit must hide in one of the holes. A wolf searches the rabbit in anticlockwise order. The first hole he get into is the one signed with 0. Then he will get into the hole every m holes. For example, m=2 and n=6, the wolf will get into the holes which are signed 0,2,4,0. If the rabbit hides in the hole which signed 1,3 or 5, she will survive. So we call these holes the safe holes.

 
Input
The input starts with a positive integer P which indicates the number of test cases. Then on the following P lines,each line consists 2 positive integer m and n(0<m,n<2147483648).
 
Output
For each input m n, if safe holes exist, you should output "YES", else output "NO" in a single line.
 
Sample Input
2
1 2
2 2
 
Sample Output
NO
YES
 
Author
weigang Lee
 
Source
 
分析:
    
    一个山围绕着n个洞,编号依次为0,1,2,...n-1,
    狼先从第一个洞开始寻找兔子,
    然后每隔m个洞寻找,依次循环,
    如果到最后每隔洞都被狼找了一遍,
    那么兔子是不安全的,要输出NO,否则输出YES。
    思路:
    求出n,m的最大公约数,如果两个数的最大公约数为1,
    那么每个洞都会被狼搜寻到,应该输出NO,否则输出YES。
   
code:

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
int gcd(int a,int b)//最大公约数
{
if (b==)
return a;
return gcd(b, a%b);
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n,m;
scanf("%d %d",&m,&n);
if(gcd(n,m)==)
printf("NO\n");
else
printf("YES\n");
}
return ;
}

HDU 1222 Wolf and Rabbit(数学,找规律)的更多相关文章

  1. HDU 1222 Wolf and Rabbit(gcd)

    HDU 1222   Wolf and Rabbit   (最大公约数)解题报告 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid= ...

  2. HDU 1222 Wolf and Rabbit(欧几里得)

    Wolf and Rabbit Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  3. hdu 1222 Wolf and Rabbit

    Problem Description There is a hill with n holes around. The holes are signed from 0 to n-1. A rabbi ...

  4. HDU 1273 漫步森林(数学 找规律)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1273 漫步森林 Time Limit: 2000/1000 MS (Java/Others)    M ...

  5. HDU 1222 - Wolf and Rabbit & HDU 1108 - [最大公约数&最小公倍数]

    水题,只是想借此记一下gcd函数的模板 #include<cstdio> int gcd(int m,int n){return n?gcd(n,m%n):m;} int main() { ...

  6. HDU 1222 Wolf and Rabbit( 简单拓欧 )

    链接:传送门 题意:狼抓兔子,狼从 0 出发沿逆时针寻找兔子,每走一步的距离为 m ,所有洞窟的编号为 0 - n-1 ,问是否存在一个洞窟使得兔子能够安全躲过无数次狼的搜捕. 思路:简单的拓展欧几里 ...

  7. hdu 2865 Polya计数+(矩阵 or 找规律 求C)

    Birthday Toy Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tota ...

  8. # E. Mahmoud and Ehab and the xor-MST dp/数学+找规律+xor

    E. Mahmoud and Ehab and the xor-MST dp/数学/找规律 题意 给出一个完全图的阶数n(1e18),点由0---n-1编号,边的权则为编号间的异或,问最小生成树是多少 ...

  9. 数学--数论--HDU - 6124 Euler theorem (打表找规律)

    HazelFan is given two positive integers a,b, and he wants to calculate amodb. But now he forgets the ...

随机推荐

  1. TOJ 1717 WOJ

    描述 Alex likes solving problems on WOJ (http://acm.whu.edu.cn/oak). As we all know, a beautiful ballo ...

  2. Android中改变Activity的不同icon:activity-alias

    Android设置title中的Icon有几种方法,介绍如下: 一种是直接在AndroidManifest.xml文件中设置android:icon属性,这种方法简单有效,应该算是我们最常用的设置Ic ...

  3. jQuery中的DOM操作——《锋利的JQuery》

    jQuery封装了大量DOM操作的API,极大提高了操作DOM节点的效率. 1.查找节点 通过我们上一节介绍了JQuery选择器,可以非常轻松地查找节点元素.不过,这时得到的是jQuery对象,只能使 ...

  4. Linux Tomcat 80端口 Port 80 required by Tomcat v8.5 Server at localhost is already in use.

    Port 80 required by Tomcat v8.5 Server at localhost is already in use. The server may already be run ...

  5. 小程序中搜索文件,阅览pdf,分享文件链接,评论表情符号

    小程序中搜索文件,阅览pdf,分享文件链接,评论表情符号 https://blog.csdn.net/hotqin888/article/details/84111389 小程序中打开网页和pdf h ...

  6. Android活动的启动模式

    1. standard 标准模式,是活动默认的启动模式,在不进行显示指定的情况下,所有活动都会自动使用这种模式. Android使用返回栈管理活动,在standard模式下,每当启动一个新的活动,它就 ...

  7. 动态网页开发jsp

    1.动态网页的优势?    ①交互性:即网页会根据用户的要求和选择而动态改变和显示内容.    ③自动更新:即无需改变页面代码,便会自动生成新的页面内容.    ④随机性:即当不同的时间.不同的人访问 ...

  8. 【Spring Boot】集成Netty Socket.IO通讯框架

    服务端 @Configuration public class NettySocketConfig { private static final Logger logger = LoggerFacto ...

  9. 003Angular2中使用ng-bootstrap

    1.检查@angular/cli版本 命令行ng -v ,版本号必须大于1.0.0-beta.24 2.新建工程 工程所在目录,命令行ng new my-app --style=scss 带style ...

  10. VS如何自动创建函数头 函数说明

    这样创建,这种方法在VS2008和VS2013下都可以. 这是效果 如何自定义格式呢? 第一步点击这个按钮 这个工具条需要安装VAssistX,如何安装这里不细说了. 第二步,点击这个按钮 第三步 点 ...