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. [C++程序设计]返回指针值的函数

    定义指针函数的一般形式为 类型名 *函数名(参数表列); 例如 int *a(int x,int y);

  2. 负载均衡集群之LVS的DR模型详解(Diretor Routing)

    LVS的默认模型:默认模型DR DR模型原理图--> 在讲DR模型要点之前,需要了解网络的相关知识: 接收的报文拆解顺序:帧(MAC)-->数据包(IP)-->数据报文(port) ...

  3. 前端上将字符串用语音读出来只能在IE上运行 其他不行 代码极少

    先保存保存自己的笔记 有高手看到求指点 <script type="text/javascript"> var VoiceObj; try { VoiceObj = n ...

  4. mongodb GUI

    官网:http://robomongo.org/ 提供Mac .Windows .Linux三种版本: robomongo界面简洁功能强大人性化:

  5. hdu 1337 The Drunk Jailer

    http://acm.hdu.edu.cn/showproblem.php?pid=1337 #include <cstdio> #include <cstring> #def ...

  6. LeetCode_Length of Last Word

    Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the l ...

  7. Ring3下Hook NtQueryDirectoryFile隐藏文件

    NTSTATUS WINAPI Hook_NtQueryDirectoryFile(IN HANDLE FileHandle,IN HANDLE Event OPTIONAL,IN PIO_APC_R ...

  8. DOS命令行 定时关机&取消定时关机

      命令行关机命令----shutdown   Windows XP的关机是由Shutdown.exe程序来控制的,位于Windows\System32文件夹中.   如果你输入"shutd ...

  9. 【Mysql 调用存储过程,输出参数的坑】

    玛德,数据行都返回过来了,就是没有输出参数!!! 扒官方设计文档:这么一段 雷死人了!!! When a stored procedure is called using MySqlCommand.E ...

  10. 年度钜献,108个大数据文档PDF开放下载

    1.大数据的开放式创新——吴甘沙 相关阅读:[PPT]吴甘沙:让不同领域的数据真正流动.融合起来,才能释放大数据的价值 下载:大数据的开放式创新——吴甘沙.pdf 2.微软严治庆——让大数据为每个人服 ...