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. 《算法导论》习题解答 Chapter 22.1-6(求universal sink 通用汇点)

    思路:设置两个游标i指向行,j指向列,如果arr[i][j]==1,则i=max{i+1,j},j++:如果arr[i][j]==0,则j=max{i+1,j+1}. 伪代码: has_univers ...

  2. WebStrom9 体验nodejs

    之前就有体验过 WebStrom8.0.3 版本,确实不错. 最喜欢的是集成了Terminal 很方便的使用NPM,今天装上发现 Terminal 死活打不上字.什么原因! WebStrom9 在wi ...

  3. MySQL中/*!40100注释

    MySQL中的注释 MySQL中的注释有三种: # 注释内容 -- 注释内容 /* 注释内容*/ 但是,在导出的SQL文件中,也会看到类似如下内容的注释: CREATE DATABASE `blog` ...

  4. Chrome隐身模式有什么用

    最近发布的Chrome浏览器,小编发现有一个个“隐身窗口”功能,那么这是什么功能呢?原来这是Chrome隐身模式!那么这个隐身模式有什么功能呢? Chrome隐身模式有什么用? 从官方的介绍来看,“隐 ...

  5. BC Harry and Magical Computer (拓扑排序)

    Harry and Magical Computer  Accepts: 350  Submissions: 1348  Time Limit: 2000/1000 MS (Java/Others) ...

  6. 剑指Offer22 判断数组是否为某二叉搜索树的后序遍历

    /************************************************************************* > File Name: 22_Sequen ...

  7. Table of Contents - Apache Commons

    Apache Commons 简述 CLI Usage of CLI Option Properties Codec 常见的编码解码 Compress Configuration2 Quick sta ...

  8. SQLServer触发器的使用

    创建: create trigger trigger_name on {table_name view_name} {for After Instead of } [ insert, update,d ...

  9. .NET中导入导出Excel总结

    前一段时间,做了Excle的导入和导出,在此记录开发思路及技术要点,以便在今后开发中参考.                                                        ...

  10. 使用Linux系统中的SSH服务

    使用Linux系统中的SSH服务 1.SSH服务应用场景 ① 可以实现对文件的上传与下载 ② 实现远程管理Linux 2.安装SSH服务器 服 务:sshd 位 置:光盘2 软 件:openssh-s ...