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
 
 
 
题意:有n个洞,这些洞围成一个圆形,狼去找兔子,按照一个规律去找,问最后还有没有剩下狼没找过洞.....
若果有就输出YES,没有就输出NO...
 
 
 
解题思路:第一眼看上去我就觉得只要狼不是按照一个一个的找的就一定会有剩下的....然后我发现我煞笔了....
      这题其实是找n和m有没有公约数,如果有公约数那么浪找完一圈之后他就会一直找这么几个洞,如果没有公约数,那么狼就总会找到的只是时间问题
 
 
 
代码如下:
 
 
 #include <stdio.h>
int gcd(int a,int b)
{
return b==?a:gcd(b,a%b);
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int m,n;
scanf("%d%d",&m,&n);
int j=gcd(n,m);
//printf("%d\n",j);
if(j==)
printf("NO\n");
else
printf("YES\n");
}
return ;
}

hdu 1222 狼和兔子的更多相关文章

  1. HDU 1222 Wolf and Rabbit(gcd)

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

  2. BZOJ 1001: [BeiJing2006]狼抓兔子

    1001: [BeiJing2006]狼抓兔子 Time Limit: 15 Sec  Memory Limit: 162 MBSubmit: 20029  Solved: 4957[Submit][ ...

  3. BZOJ1001: [BeiJing2006]狼抓兔子 [最小割 | 对偶图+spfa]

    1001: [BeiJing2006]狼抓兔子 Time Limit: 15 Sec  Memory Limit: 162 MBSubmit: 19528  Solved: 4818[Submit][ ...

  4. 【BZOJ1001】狼抓兔子

    1001: [BeiJing2006]狼抓兔子 Time Limit: 15 Sec  Memory Limit: 162 MBSubmit: 7530  Solved: 1724[Submit][S ...

  5. BZOJ 1001 [BeiJing2006] 狼抓兔子(平面图最大流)

    题目大意 现在小朋友们最喜欢的"喜羊羊与灰太狼",话说灰太狼抓羊不到,但抓兔子还是比较在行的.而且现在的兔子还比较笨,它们只有两个窝,现在你做为狼王,面对下面这样一个网格的地形: ...

  6. BZOJ-1001 狼抓兔子 (最小割-最大流)平面图转对偶图+SPFA

    1001: [BeiJing2006]狼抓兔子 Time Limit: 15 Sec Memory Limit: 162 MB Submit: 14686 Solved: 3513 [Submit][ ...

  7. 【BZOJ】【1001】 【BJOI2006】狼抓兔子

    平面图最小割->对偶图最短路 平面图最小割转对偶图最短路= = 想到了就比较好写了…… 可能是我对区域的标号方式比较奇特?反正我没有特判n==1||m==1也能过2333(机智吧-(滚开啦你个自 ...

  8. 【BZOJ】1001: [BeiJing2006]狼抓兔子 Dinic算法求解平面图对偶图-最小割

    1001: [BeiJing2006]狼抓兔子 Description 左上角点为(1,1),右下角点为(N,M)(上图中N=4,M=5).有以下 三种类型的道路 1:(x,y)<==>( ...

  9. BZOJ_1001_狼抓兔子_(平面图求最小割+对偶图求最短路)

    描述 http://www.lydsy.com/JudgeOnline/problem.php?id=1001 1001: [BeiJing2006]狼抓兔子 Time Limit: 15 Sec   ...

随机推荐

  1. (转)JavaScript 中对变量和函数声明的“提前(hoist)”

    变量声明“被提前” JavaScript 的语法和 C .Java.C# 类似,统称为 C 类语法.有过 C 或 Java 编程经验的同学应该对“先声明.后使用”的规则很熟悉,如果使用未经声明的变量或 ...

  2. Kafka删除逻辑

    Kafka的删除逻辑请参见:http://www.cnblogs.com/gaopeng527/p/4950956.html

  3. 让UIScrollView、UITableView的滚动条一直显示

    先用xcode5.1.1或更低版本创建一个Category,如图: 然后拷贝以下代码到刚创建的UIImageView+ForScrollView.m文件中: - (void) setAlpha:(fl ...

  4. 编译项目报错: Ignoring file / xxx , missing required architecture i386 in file / xxx (2 slices)

    .lib 或者 .a需用于真机版本,也就是ARM7的,如果你编译的是模拟器就会出现这个错误: 选择真机调试即可 .

  5. BootStraps 布局

    <div class="container"> //创建一个容器 <div class="row">  //创建行,每行总有12个格数 ...

  6. js解析xml,获取XMl标签属性值

    <script type="text/javascript"> var xml="<?xml version=\"1.0\" enc ...

  7. java 集合(list、set、map)的特点

    集合相关的类有一大堆,一般也只用到常用的方法增删改查,而且它它们的方法名也基本一样,所以一直都不知道什么时候用什么集合, 今天趁有空特意从网上整理资料方便日后回忆. 一.List:.有顺序以线性方式存 ...

  8. php读取目录下的文件

    工作需要写了一个读取指定目录下的文件,并显示列表,点击之后读取文件中的内容 高手拍砖,目录可以自由指定,我这里直接写的是获取当前文件目录下面的所有文件 <?php /** * 读取指定目录下面的 ...

  9. ArrayList与List对象用法与区别

    比如: 代码如下 复制代码 string[] s=new string[3];//赋值s[0]="a";s[1]="b";s[2]="c"; ...

  10. 济南学习 Day2 T2 am

    [问题描述]有N个数,随机选择一段区间,如果这段区间的所有数的平均值在[l,r]中则你比较厉害.求你比较厉害的概率.[输入格式]第一行有三个数N,l,r,含义如上描述.接下来一行有