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. jQuery模拟瀑布流布局

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  2. linux修改文件权限

    ubuntu 下修改文件访问权限 Ubuntu下修改目录权限命令如下: chmod 600 name (只有所有者有读和写的权限) chmod 644 name (所有者有读和写的权限,组用户只有读的 ...

  3. T-SQL 脚本

    1.USE语句 USE语句用于设置当前数据库,如果没有USE语句,那么就由执行脚本的任何用户来确定执行脚本时当前数据库是正确的.如果只是一个通用脚本,那么省去USE语句实际上可能更有益.通常,如果在脚 ...

  4. javascript之String

    一.构造函数 new String(value) //构造函数 function String(value) //转换函数 二.属性 length 该字符串中的字符数 var str = new St ...

  5. qsort排序算法

      七种qsort排序方法 <本文中排序都是采用的从小到大排序> 一.对int类型数组排序 int num[100]; Sample: int cmp ( const void *a ,  ...

  6. Word Break I II

    Word Break Given a string s and a dictionary of words dict, determine if s can be segmented into a s ...

  7. JS代码混淆 支持PHP .NET PERL

    官方  http://dean.edwards.name/packer/ Also available as .NET, perl and PHP applications. .NET实例下载地址:h ...

  8. cc150 Chapter 2 | Linked Lists 2.6 Given a circular linked list, implement an algorithm which returns node at the beginning of the loop.

    2.6Given a circular linked list,  implement an algorithm which returns the node at the beginning of ...

  9. hdu 4502 吉哥系列故事——临时工计划_简单dp

    题意:        俗话说一分钱难倒英雄汉,高中几年下来,吉哥已经深深明白了这个道理,因此,新年开始存储一年的个人资金已经成了习惯,不过自从大学之后他不好意思再向大人要压岁钱了,只能把唯一的希望放到 ...

  10. django 启动和请求

    Django运行方式 调试模式 直接 python manage.py runserver python manage.py runserver python manage.py runserver ...