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. WEB ICON 的探讨

    一般考虑到webicon 就是cssSprite和自定义font:本文基于下述而总结和进行分析,如有笔误有望指出,谢谢 在线教程:用字体在网页中画ICON图标 http://www.imooc.com ...

  2. CSS3-旋转齿轮

    CSS3-旋转齿轮 查看DEMO 通过 CSS3,我们能够创建动画,这可以在许多网页中取代动画图片.Flash 动画以及 JavaScript. 先来认识一下css3的animation animat ...

  3. java学习之内省

    反射加内省解决耦合问题 package com.gh.introspector; /** * JavaBean * @author ganhang * */ public class Dog { pr ...

  4. 版本管理工具:linux下svn的基本使用

    参考: linux下安装SVN    http://jingyan.baidu.com/article/3c343ff7039de20d37796306.html svn客户端使用linux篇  ht ...

  5. 如何删除openfire for苹果,彻底卸载!

    早前在MAC上安装了一个名为openfire的服务插件,用这个进行一些插件安装和设置,使ichat能登录MSN帐号.但现在最新的MSN已经有所改善,支持视频与语音,离线信息接收.而openfire有个 ...

  6. Android使用HttpClient向服务器传输文件

    HttpClient是Apache Jakarta Common下的子项目,可以用来提供功能丰富的支持HTTP协议的客户端编程工具包,这几天写客户端的时候遇到个问题,“客户端需要向服务器发送Post请 ...

  7. Week13(12月2日):又到了那个点,期末了~~~~

    Part I:提问 =========================== 1.ASP.NET MVC是微软.NET平台上的一个(      ). A.语言    B.集成开发环境    C.Web开 ...

  8. ASP.NET MVC进阶之路:深入理解Controller激活机制并使用Ioc容器创建对象

    本文标题说是"深入理解Controller"其实有点“标题党”的味道了.本篇只会探讨"Controller"的激活机制,也就是如何创建Controller的并调 ...

  9. 基于visual Studio2013解决算法导论之053图的邻接表表示

     题目 图的邻接表表示 解决代码及点评 // 图的邻接表表示.cpp : 定义控制台应用程序的入口点. // #include <iostream> #include <sta ...

  10. #AzureChat - 自动伸缩和虚拟机

    我们很高兴地推出再一次 #AzureChat,这是 @WindowsAzure 团队为您精心打造的一个在 Twitter 上进行的聊天活动! #AzureChat 专注于云计算的各个方面以及云开发的最 ...