http://acm.hdu.edu.cn/showproblem.php?pid=1222

Wolf and Rabbit

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

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
 

题解:就是求n和m 是否互质,求gcd(n,m)是否等于1即可

代码:

 #include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
int gcd (int a , int b)
{
return b==? a :gcd(b,a%b);
}
int main()
{
int n , m ;
int t ;
cin>>t;
while(t--)
{
scanf("%d%d",&n,&m);
if(gcd(n,m)==)
cout<<"NO"<<endl;
else cout<<"YES"<<endl;
}
return ;
}

Wolf and Rabbit的更多相关文章

  1. Wolf and Rabbit(gcd)

    Wolf and Rabbit Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  2. HDU 1222 Wolf and Rabbit(gcd)

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

  3. HDU 1222 Wolf and Rabbit(欧几里得)

    Wolf and Rabbit Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  4. gcd(最大公约数)lcm(最小公倍数)E - Wolf and Rabbit

    1.gcd 递归实现 int gcd(int i,int j){ if(j==0) return i; else return gcd(j,i%j);} 2.lcm int gcd(int i,int ...

  5. 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 ...

  6. 转化为用欧几里得算法判断互质的问题D - Wolf and Rabbit

    Description There is a hill with n holes around. The holes are signed from 0 to n-1. A rabbit must h ...

  7. HDU Wolf and Rabbit

    Description There is a hill with n holes around. The holes are signed from 0 to n-1. A rabbit must h ...

  8. GCD(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 ...

  9. HDU 1222 Wolf and Rabbit(数学,找规律)

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission( ...

随机推荐

  1. C:数据结构与算法之顺序表

    顺序表作为数据结构的开端,说明这里面很多基础要学,初学者一开始都会混淆,今天我们来一步一步来建立一个完整的顺序表,可以任我们控制的顺序表,首先先定义一个顺序表 /* Note:Your choice ...

  2. office------------word邮件合并(word2016版)

    虽然本人是学计算机的,但是office技能很一般,最近工作中用到了邮件合并这一功能,记录下来与大家分享. 我用到的邮件合并就是word中定好模板,从excel中批量导入数据,现实生活中,在录取通知书打 ...

  3. ElasticSearch 学习记录之父子结构的查询

    父子结构 父亲type属性查询子type 的类型 父子结构的查询,可以通过父亲类型的字段,查询出子类型的索引信息 POST /product/_search { "query": ...

  4. 在一个终端后台运行的进程在新的终端中使用job不会被发现

    我在一个终端后台运行了一个程序.之后由于工作需要又新开了一个新的终端.在新的终端中,我想查看后台程序的运行状态,输入jobs时,发现没有后台任务运行.难道我的程序死掉了?我接着top了下,发现我的后台 ...

  5. Vue 子组件无法使用 $emit 向父组件传参

    问题描述:

  6. dubbo filter链构建过程

    public <T> Exporter<T> export(Invoker<T> invoker) throws RpcException { if (Consta ...

  7. Redis学习笔记(一)关于在windows64位环境下的安装学习使用

    前言 由于工作需要,目前我正在学习使用Redis.我当时学习Redis就从网上下载了点资料就开始学习了.入门看的是<REDIS入门指南>,这本书个人觉得很适合新手用来学习接触.根据书上的引 ...

  8. Html鼠标右键菜单代码

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  9. 深入理解JVM(五)——垃圾回收器

    轻松学习JVM(五)——垃圾回收器 上一篇我们介绍了常见的垃圾回收算法,不同的算法各有各的优缺点,在JVM中并不是单纯的使用某一种算法进行垃圾回收,而是将不同的垃圾回收算法包装在不同的垃圾回收器当中, ...

  10. 在地铁上看了zabbix 的书发现 "报警执行远程命令"

    在地铁上看了zabbix 的书发现 "报警执行远程命令" 远程命令整个过程:  items -> triggers -> action -> remote com ...