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

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
 
Author
weigang Lee
 
Source
 
分析:
    
    一个山围绕着n个洞,编号依次为0,1,2,...n-1,
    狼先从第一个洞开始寻找兔子,
    然后每隔m个洞寻找,依次循环,
    如果到最后每隔洞都被狼找了一遍,
    那么兔子是不安全的,要输出NO,否则输出YES。
    思路:
    求出n,m的最大公约数,如果两个数的最大公约数为1,
    那么每个洞都会被狼搜寻到,应该输出NO,否则输出YES。
   
code:

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
int gcd(int a,int b)//最大公约数
{
if (b==)
return a;
return gcd(b, a%b);
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n,m;
scanf("%d %d",&m,&n);
if(gcd(n,m)==)
printf("NO\n");
else
printf("YES\n");
}
return ;
}

HDU 1222 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. 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 ...

  4. HDU 1273 漫步森林(数学 找规律)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1273 漫步森林 Time Limit: 2000/1000 MS (Java/Others)    M ...

  5. 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() { ...

  6. HDU 1222 Wolf and Rabbit( 简单拓欧 )

    链接:传送门 题意:狼抓兔子,狼从 0 出发沿逆时针寻找兔子,每走一步的距离为 m ,所有洞窟的编号为 0 - n-1 ,问是否存在一个洞窟使得兔子能够安全躲过无数次狼的搜捕. 思路:简单的拓展欧几里 ...

  7. hdu 2865 Polya计数+(矩阵 or 找规律 求C)

    Birthday Toy Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tota ...

  8. # E. Mahmoud and Ehab and the xor-MST dp/数学+找规律+xor

    E. Mahmoud and Ehab and the xor-MST dp/数学/找规律 题意 给出一个完全图的阶数n(1e18),点由0---n-1编号,边的权则为编号间的异或,问最小生成树是多少 ...

  9. 数学--数论--HDU - 6124 Euler theorem (打表找规律)

    HazelFan is given two positive integers a,b, and he wants to calculate amodb. But now he forgets the ...

随机推荐

  1. POJ 3468——A Simple Problem with Integers——————【线段树区间更新, 区间查询】

    A Simple Problem with Integers Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 86780   ...

  2. windows下libcurl+openssl编译与使用配置

    之前使用过libcurl, 编译也是最简单的版本, 不需要openssl, 即不需要支持https, 所以编译和使用都很正常. 但要使用openssl就很麻烦了, 我花了差不多两天去编译和调用, 记录 ...

  3. NDK编译不同架构的参数

    随着Android的蓬勃发展, CPU的架构也越来越多. 早期只支持ARMv5, 截至目前, 支持的架构已达三类七种: ARM(ARMv5,ARMv7 (从2010年起),ARMv8), x86(x8 ...

  4. small zhishi

    \\192.168.1.201\d$\Data 访问远程计算机文件资源管理器

  5. 模糊查询-动态参数,防SQL注入

    WHERE("title like '%'+#{keyWord}+'%'"); -MS SQL WHERE("title like concat('%',#{keyWor ...

  6. CentOS初使用命令总结

    最近买了一台aliyun(ECS服务器)用来学习使用,初次使用难免要走弯路.遇到一些问题好长时间解决不了,结果经人指点豁然开朗.于是乎,总结了一些新生上路经验. 首先要解决的问题是:通过PuTTY.S ...

  7. 常用DOM结构方法总结

    ---内容开始--- 获取元素的方法: getElementById() 通过ID名获取元素 getElementsByTagName() 通过元素(标签)名称 getElementsByClassN ...

  8. 怎样在vs2013和vs2015中实现自动编译sass

    Visual Studio不论是2013版本还是2015版本要自动编译都需要添加扩展. 添加扩展的方法,路径“工具”->“扩展和更新”,在打开的窗口“搜索”你需要的扩展根据提示“下载”和“安装” ...

  9. Tomcat 数据源的原理、配置、使用

    1.数据源的作用及操作原理 在程序代码中使用数据源是可以提升操作性能的,这种性能的提升依靠于运行的原理. 传统JDBC操作步骤 1.加载数据库驱动程序,数据库驱动程序通过CLASSPATH配置: 2. ...

  10. 快速开始Python/WSGI应用程序

    快速开始Python-wsig应用程序 官方参考文档 安装 uwsgi 安装 pip install uwsgi uwsgi --version # 查看 uwsgi 版本 测试 uwsgi 是否正常 ...