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. Java流和文件

    File类:java.io包下与平台无关的文件和目录 java可以使用文件路径字符串来创建File实例,文件路径可以是绝对路径,也可以是相对路径,默认情况下,相对路径是依据用户工作路径,通常就是运行J ...

  2. hibernate事务管理 (jdbc jta)

    hibernate的两种事务管理jdbc 和jta方式.下边说说两者的区别一.说明一下jdbc和jta方式事务管理的区别:JDBC事务由Connnection管理,也就是说,事务管理实际上是在JDBC ...

  3. C# 读写xml、excel、word、ppt、access

    C# 读写xml.excel.word.access 这里只是起个头,不做深入展开,方便以后用到参考 读写xml,主要使用.net  的xml下的document using System;using ...

  4. 微服务学习笔记二:Eureka服务注册发现

    Eureka服务注册发现 服务发现:云端负载均衡,一个基于 REST 的服务,用于定位服务,以实现云端的负载均衡和中间层服务器的故障转移. 1. Service Discovery: Eureka S ...

  5. 概述File i/o

    1.File对象既可表示文件,也可表示目录(文件夹). 2. 创建一个File对象 File file = new File (String pathName[文件路径名]); 3.在Windows操 ...

  6. Flowchart

    1. 工具可使用 https://www.processon.com 2.

  7. master.dbo.spt_values

    ,@date)) /*day--------------------200911012009110220091103200911042009110520091106200911072009110820 ...

  8. matlab练习程序(随机游走图像)

    随机游走类似布朗运动,就是随机的向各个方向走吧. 虽然代码没什么技术含量,不过产生的图像实在太漂亮了,所以还是贴上来吧. 产生的图像: matlab代码如下: clear all;close all; ...

  9. Android学习——SharedPreferences

    接下来的几个博文,来介绍安卓中的数据存储方式,安卓中的数据存储主要有四种方式: 1.SharedPreferences 2.SQLite 3.Content Provider 4.File 这篇博文主 ...

  10. file中mkdirs和mkdir的区别-文件上传

    mkdirs()可以建立多级文件夹, mkdir()只会建立一级的文件夹, 如下: new File("/tmp/one/two/three").mkdirs(); 执行后, 会建 ...