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个洞 0。。n-1;
狼从0开始每m个洞进去一次 
问兔子是否存活,
其实就是判断n,m的最大公约数是否为1
仔细想想吧
#include<iostream>
using namespace std;
int gcd(int a,int b){
return b==?a:gcd(b,a%b);
}
int main(){
int t,n,m;cin>>t;
while(t--){
cin>>m>>n;
if(m==)cout<<"NO"<<endl;
else {
if(gcd(n,m)==)cout<<"NO"<<endl;
else cout<<"YES"<<endl;
}
}
return ;
}
 
 

HDU 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. Wolf and Rabbit

    http://acm.hdu.edu.cn/showproblem.php?pid=1222 Wolf and Rabbit Time Limit: 2000/1000 MS (Java/Others ...

  4. Wolf and Rabbit(gcd)

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

  5. gcd(最大公约数)lcm(最小公倍数)E - Wolf and Rabbit

    1.gcd 递归实现 int gcd(int i,int j){ if(j==0) return i; else return gcd(j,i%j);} 2.lcm int gcd(int i,int ...

  6. 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 ...

  7. HDU 1222 Wolf and Rabbit(数学,找规律)

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission( ...

  8. 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() { ...

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

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

随机推荐

  1. Maven Jrebel 多模块热部署方案

    近期在构建maven多模块项目时,发现web module依赖的其它模块,每次都要clean install成一个jar包,然后运行web module才能加载. 本生jrebel是配置在了web m ...

  2. 链接分析算法之:HillTop算法

      链接分析算法之:HillTop算法     Hilltop算法是由Krishna Baharat 在2000年左右研究的,于2001年申请专利,但是有很多人以为Hilltop算法是由谷歌研究的.只 ...

  3. 基于visual Studio2013解决C语言竞赛题之0304整除数

      题目 解决代码及点评 按照题目要求,判断数值对3和5取模的结果,是否为0 #include <stdio.h> #include <stdlib.h> void m ...

  4. route-over VS mesh-under

    近期在网上看到一篇专门介绍route-over和Mesh-under的论文,介绍的比較具体: ip=183.63.119.35&id=1582643&acc=ACTIVE%20SERV ...

  5. IBM 中国研究院面试经历

    继上次面试MSRA失败后,严重刺激了我幼小的心灵.从此苦学算法准备面试很多其它其它的公司刷一刷Offer以解心 头之恨. 这个带来的IBM 中国研究院的面试经历. IBM的面试相比于MSRA.简直就是 ...

  6. Spring IOC和DI原理讲解并制作LazyCoder版的Spring (一)

    转载请注意出处:http://blog.csdn.net/zcm101 写在前面的话 最近,给项目组成员培训了Spring 控制反转和依赖注入的原理,并自己做了个Lazy Coder版的Spring, ...

  7. ThinkPHP - CURD增删改查 - 实例

    目录结构:

  8. 【Tomcat】本地域名访问设置

    原路径:localhost:8080/tidyko 1.去掉8080端口 打开%TOMCAT_HOME%/conf/server.xml 修改里面的 <Connector connectionT ...

  9. 【DWR】Annotation入门

    DWR简介:http://baike.baidu.com/view/73492.htm?fr=aladdin DWR2.0以后新增加了JDK5的注解(Annotation)功能,使用注解功能之后可以从 ...

  10. 在主函数中提示用户输入用户名和密码。另写一方法来判断用户输入是否正确。该方法分别返回一个bool类型的登录结果和和一个string类型的登录信息。如登录成功,返回true及“登录成功”,若登录失败则返回false及“用户名错误”或“密码错误”(使用out参数)

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...