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. JS中数组的方法

    1. join() Array.join() 是 String.split() 的逆向操作 var arr = [1, 2, 3] arr.join()// "1,2,3" arr ...

  2. tideways+xhgui搭建php 7的性能测试环境

    前言 我之前使用的是xhprof+xhgui分析线上环境的性能,然而PHP版本升级到PHP 7之后,xhprof已经不可用,于是改用tideways+xhgui,这实际上也是PHP7下开源方案的唯一选 ...

  3. 通过 备份文件 恢复/迁移 gitlab

    =============================================== 2017/10/20_第1次修改                       ccb_warlock = ...

  4. AJAX请求真的不安全么?谈谈Web安全与AJAX的关系。

    开篇三问 AJAX请求真的不安全么? AJAX请求哪里不安全? 怎么样让AJAX请求更安全? 前言 本文包含的内容较多,包括AJAX,CORS,XSS,CSRF等内容,要完整的看完并理解需要付出一定的 ...

  5. Python 错误 UnicodeEncodeError: 'ascii' codec can't encode character 的解决方案

    一.使用workbook.get_sheet_by_name(name) 获取excel一个工作表时,发生字符集解析的错误. 网上搜集解决方案为添加以下三句: import sys reload(sy ...

  6. oracle自动备份_expdp_Linux

    [oracle@hbsjxtdb1 ~]$ crontab -e 0 4 * * * /backup/script/backupexpdp.sh [oracle@hbsjxtdb1 ~]$ cront ...

  7. [编织消息框架][JAVA核心技术]动态代理应用1

    前面几篇介绍,终于到了应用阶段啦,我们来做一个RPC来加强学过的知识 做基础核心时先确定解决什么问题,提供什么服务,同将来扩展等 rpc 分两部份,一个是调用者,另一方是服务提供者 调用者只关心那个服 ...

  8. PHP 购物车 php闭包 array_walk

    <?php class Cart { const PRICE_BUTTER = 1.00; const PRICE_MILK = 3.00; const PRICE_EGGS = 6.95; p ...

  9. MySQL视图,触发器,事务,存储过程,函数

    create triggr triafterinsertcmdlog after insert on cmd_log FOR EACH ROW trigger_body .#NEW : 代表新的记录 ...

  10. 初识BASH SHELL

    什么是Shell shell翻译成中文就是"壳"的意思.简单来说就是shell是计算机用户与操作系统内核进行"沟通"的一种工具.Windows系统中有power ...