Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

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

程序分析:由上面的标题可以知道是求最最大公约数,但是一定不要超时,我有递归时间只用了0MS,其实这里我用了long long 型 ,其实没必要,int型也是可以的。还有我的if语句也是个出错点,就是因为这个答案一直不对。

程序代码:

#include<iostream>
#include<algorithm>
using namespace std;
#include<cstdio>
#define ll _int64
int gcd(int n,int m)
{ return m==?n:gcd(m,n%m); }
int main()
{
int T;
ll n,m,k;
cin>>T;
while(T--)
{
scanf("%I64d%I64d",&n,&m);
if(n<m)
swap(n,m);
k=gcd(n,m);
if(k==) cout<<"NO"<<endl; else cout<<"YES"<<endl; }
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. GCD and LCM HDU 4497 数论

    GCD and LCM HDU 4497 数论 题意 给你三个数x,y,z的最大公约数G和最小公倍数L,问你三个数字一共有几种可能.注意123和321算两种情况. 解题思路 L代表LCM,G代表GCD ...

  3. HDU 2503 (数论,最大公约数)

    a/b + c/d Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

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

  5. HDU 1222

    题意: 一头狼和一头兔子在一座山中,给你一个数n表示洞的个数,编号从0~n-1.兔子可以随意躲在其中一个洞中,狼每次都从编号为0的洞出发,接下来走到第m个洞中,问兔子能不能活下来,即不被狼吃掉.例如: ...

  6. HDU 4497 数论+组合数学

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4497 解题思路:将满足条件的一组x,z,y都除以G,得到x‘,y',z',满足条件gcd(x',y' ...

  7. hdu 1222 狼和兔子

    Description There is a hill with n holes around. The holes are signed from 0 to n-1. A rabbit must h ...

  8. hdu 4542 数论 + 约数个数相关 腾讯编程马拉松复赛

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=4542 小明系列故事--未知剩余系 Time Limit: 500/200 MS (Java/Others) ...

  9. (数论 最大公约数 最小公倍数) codeVs 1012 最大公约数和最小公倍数问题

    题目描述 Description 输入二个正整数x0,y0(2<=x0<100000,2<=y0<=1000000),求出满足下列条件的P,Q的个数 条件:  1.P,Q是正整 ...

随机推荐

  1. Cortex-M3动态加载三(模块调用系统函数)

    在我的arm动态加载实验中需要解决一个模块调用系统函数的问题,可以使用以下的一个方法.将系统函数固定在某一段地址空间,然后导出这一块的符号表到符号文件中,要记载的模块link的时候使用这个符号表文件, ...

  2. (iOS)Storyboard/xib小技巧

    1.选择被view覆盖住的view 当你想直接在view中选择自己想要的元素时,但是又碍于一个view上叠加的元素太多很难直接选中,那么在这时,你同时按住键盘上的shift和 control键,然后在 ...

  3. 《转》java动态代理(JDK和cglib)

    该文章转自:http://www.cnblogs.com/jqyp/archive/2010/08/20/1805041.html JAVA的动态代理 代理模式 代理模式是常用的java设计模式,他的 ...

  4. Android Studio 代码混淆

    新建一个项目,Android Studio默认关闭代码混淆开关,在build.gradle文件中,如下图所示的minifyEnabled 开关,因此如果需要混淆代码,需将false改为true,然后在 ...

  5. 动画画圆的效果特效ios源码

    一款不错的支持动画画圆的效果特效源码,该效果实现了动画画圆,还可以扩展成画其他平面图形功能等,大家可以下载看看吧. //定义所需要画的图形  -(void)intiUIOfView  {      U ...

  6. nodejs - json序列化&反序列化示例

    // demo-json.js var obj = { "name": "LiLi", "age": 22, "sex" ...

  7. 具体解释http 协议

    HTTP协议的主要特点可概括例如以下: 1.支持客户/server模式. 2.简单高速:客户向server请求服务时,仅仅需传送请求方法和路径.请求方法经常使用的有GET.HEAD.POST.每种方法 ...

  8. window.open 使用方法

    window.open(url,name,features,replace); //parameters 解释: URL:需要打开的URL Name:打开URL的标题 Feature:控制窗口大小的参 ...

  9. 转载ajax

    写在前面的话: 用了很久的Asp.Net Ajax,也看了段时间的jquery中ajax的应用,但到头来,居然想不起xmlHttpRequest的该如何使用了. 以前记的也不怎么清楚,这次就重新完整的 ...

  10. Java中Iterator(迭代器)的用法及其背后机制的探究

    在Java中遍历List时会用到Java提供的Iterator,Iterator十分好用,原因是: 迭代器是一种设计模式,它是一个对象,它可以遍历并选择序列中的对象,而开发人员不需要了解该序列的底层结 ...