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. Linux 中执行命令

    第一步: 在txt文件(文件名为cmd_file)中写入代码:echo this is content! 第二步: 授权chmod 555 cmd_file 第三步: 运行 ./cmd_file -- ...

  2. java核心技术学习笔记之一程序设计概述

    Java 核心技术之一程序设计概述 一.   Java语言的特点 简单行 :取经于C++,排除了C++不常用的指针.结构等,增加垃圾回收. 面向对象:与C++不同是单继承,但是可以继承多接口.完全面向 ...

  3. 转: angular编码风格指南

    After reading Google's AngularJS guidelines, I felt they were a little too incomplete and also guide ...

  4. cocos2dx CCEditBox

    CCTextFieldTTF是一个简单的封装,用起来不是那么便利,在cocos2dx的extension里,对输入框有更加简单使用的类,那就是CCEditBox 上代码先: bool EditBox0 ...

  5. linux 在终端中打开图形化文件管理器

    虽然终端十分强大,但在少数使用终端的时候,会突然需要图形化文件管理器的帮忙. 命令: xdg-open "dir" 例如 xdg-open ./ 用图形化文件管理器打开当前文件夹 ...

  6. swith

    “开关”(Switch)有时也被划分为一种“选择语句”.根据一个整数表达式的值,switch语句可从一系列代码选出一段执行.它的格式如下: switch(整数选择因子) { case 整数值1 : 语 ...

  7. Java内存模型-jsr133规范介绍

    原文地址:http://www.cnblogs.com/aigongsi/archive/2012/04/26/2470296.html; 近期在看<深入理解Java虚拟机:JVM高级特性与最佳 ...

  8. html网页编码问题

    之前碰到过一些html编码乱码问题,都理解的模模糊糊,问了别人解释的也是模模糊糊.近期要做前端这个问题研究了下仅仅须要两句话就能非常清楚的解释了(之前问的那些人是不是自己都没理解非常郁闷.) < ...

  9. C++ signal的使用

    1.头文件 #include  <signal.h> 2.功能 设置某一信号的对应动作 3.函数原型 typdef  void  (*sighandler_t )(int); sighan ...

  10. 关于css的默认宽度

    <div class="boxa"> <div class="boxb">我是div</div> </div> ...