Wolf and Rabbit

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 5922    Accepted Submission(s):
2972

点我

Problem 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
如果不互质则会循环下去,互质则会存在位置不能到达
 #include <iostream>
#include <cstring>
using namespace std;
#define LL long long
LL gcd(LL x,LL y)
{
if(x<y)
return gcd(y,x);
if(y==)
return x;
return gcd(y,x%y);
}
int main()
{
LL n,m;
int k;
cin>>k;
while(k--)
{
cin>>m>>n;
LL p=gcd(m,n);
// cout<<p<<endl;
if(p==)
cout<<"NO\n";
else
cout<<"YES\n";
}
return ;
}

Wolf and Rabbit(gcd)的更多相关文章

  1. HDU 1222 Wolf and Rabbit(gcd)

    HDU 1222   Wolf and Rabbit   (最大公约数)解题报告 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid= ...

  2. IOS多线程(GCD)

    简介 Grand Central Dispatch 简称(GCD)是苹果公司开发的技术,以优化的应用程序支持多核心处理器和其他的对称多处理系统的系统.这建立在任务并行执行的线程池模式的基础上的.它首次 ...

  3. IOS学习之十七:Grand Central Dispatch(GCD)编程基础

    IOS学习之十七:Grand Central Dispatch(GCD)编程基础   有过编程经验的人,基本都会接触到多线程这块. 在java中以及Android开发中,大量的后台运行,异步消息队列, ...

  4. Swift - 多线程实现方式(3) - Grand Central Dispatch(GCD)

    1,Swift继续使用Object-C原有的一套线程,包括三种多线程编程技术: (1)NSThread (2)Cocoa NSOperation(NSOperation和NSOperationQueu ...

  5. 4.3 多线程进阶篇<中>(GCD)

    更正:队列名称的作用的图中,箭头标注的有些问题,已修正 本文并非最终版本,如有更新或更正会第一时间置顶,联系方式详见文末 如果觉得本文内容过长,请前往本人 “简书” 本文源码 Demo 详见 Gith ...

  6. 求最大公约数(GCD)的两种算法

    之前一直只知道欧几里得辗转相除法,今天学习了一下另外一种.在处理大数时更优秀的算法--Stein 特此记载 1.欧几里得(Euclid)算法 又称辗转相除法,依据定理gcd(a,b)=gcd(b,a% ...

  7. [BZOJ 2257][JSOI2009]瓶子和燃料 题解(GCD)

    [BZOJ 2257][JSOI2009]瓶子和燃料 Description jyy就一直想着尽快回地球,可惜他飞船的燃料不够了. 有一天他又去向火星人要燃料,这次火星人答应了,要jyy用飞船上的瓶子 ...

  8. 紫书 习题 10-8 UVa 10622(gcd)

    把这个数质因数分解然后求因子个数的gcd就ok了. 一些细节 (1)这道题的质因数不需要存下来,每一次做完取一次gcd就ok了 (2)判断奇偶用ans & 1的时候要加括号, 位运算要注意括号 ...

  9. 数论-质因数(gcd) UVa 10791 - Minimum Sum LCM

    https://vjudge.net/problem/UVA-10791/origin 以上为题目来源Google翻译得到的题意: 一组整数的LCM(最小公倍数)定义为最小数,即 该集合的所有整数的倍 ...

随机推荐

  1. 《javascript高级程序设计》笔记4.1.4:检测类型

    javascript类型检测这节主要讲了typeof和instanceof操作符. 一.typeof操作符: 1.typeof在检测基本数据类型时十分方便,针对4种基本数据类型string.numbe ...

  2. 话说 MAX_FILE_SIZE

    PHP关于文件上传部分,特别提到表单隐藏域:MAX_FILE_SIZE,意思是接收文件的最大尺寸.文档中给出的例子如下: <form enctype="multipart/form-d ...

  3. 谈一谈JVM内存JAVA_OPTS参数

    最近几个月,做的性能测试项目中,发现了一些内存方面的问题,其中有涉及到对JBOSS里的JAVA_OPTS配置,例如一下所示: JAVA_OPTS="-server -Xms1536m -Xm ...

  4. scp和pscp

    在linux中,我们常用scp命令传输文件: 如以下实例,我们想把当前服务器文件abc.sql传输到192.168.1.1服务器上,我们可以执行以下命令: scp /home/person/hww/a ...

  5. 伪静态(URL重写)

    伪静态在可以使用数据库提供更强大的功能的同时,将很长很复杂的链接变成简短的静态链接形式,迎合搜索引擎方便搜索引擎蜘蛛(Spider)来抓取网页上的相关内容,提高页面被搜索引擎索引收录的比率,为用户提供 ...

  6. A Distributed Multichannel MAC Protocol for Multihop Cognitive Radio Networks

    2010 这个呢,就是time slotted的DSA网络MAC层协议. 跟上一篇单纯的Multi Channel实现类似,不过这里是CR网络,因为多了嗅探等操作. 简单的说,time slotted ...

  7. QObject的event函数就可以改写对消息的处理

    一个既自己处理Tab事件又自己处理某些按键事件,然后将其它不需自己处理的事件转发给基类处理: bool MyWidget::event(QEvent *event){ if (event->ty ...

  8. aliyun 安装图形

    yum安装图形界面: 1) yum groupinstall "X Window System" yum install xclock yum groupinstall -y &q ...

  9. 异常:ERROR [org.hibernate.proxy.BasicLazyInitializer] - CGLIB Enhancement failed...

    ERROR [org.hibernate.proxy.BasicLazyInitializer] - CGLIB Enhancement failed: com.movie.类 放到lib 包下 \W ...

  10. ERROR: HHH000388: Unsuccessful: create table

    做SSH整合的时候,总是出现错误信息: 类似这样: : HHH000388: Unsuccessful: create table right (right_code varchar(255) not ...