Wolf and Rabbit

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

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
/*************************************************************************
> File Name: HDU1222.cpp
> Author: LyuCheng
> Created Time: 2017年10月18日 星期三 21时11分08秒
************************************************************************/
/*
* 题意:大灰狼追小白兔。小白兔可以躲起来的洞绕成一个圈,大灰狼从0这个点出发,
* 每次走m个,问这些洞有木有可以不被狼找到的。
* 思路:如果gcd(n,m)不等于1的话,那么最小公倍数不为n*m,那么用x(x<n)次,大灰
* 狼就会跑到出发位置,肯定不会遍历n个点.
* */
#include <bits/stdc++.h> using namespace std; int t;
int a,b; int main(){
scanf("%d",&t);
while(t--){
scanf("%d%d",&a,&b);
if(__gcd(a,b)==){
puts("NO");
}else{
puts("YES");
}
}
return ;
}

HDU1222Wolf and Rabbit(GCD思维)的更多相关文章

  1. hdu1222Wolf and Rabbit (公约数的巧题)

    一个很坑的问题,想到点子上很好解决,想不到的话头破也不一定能做出来. There is a hill with n holes around. The holes are signed from 0 ...

  2. CF1025B Weakened Common Divisor【数论/GCD/思维】

    #include<cstdio> #include<string> #include<cstdlib> #include<cmath> #include ...

  3. 【CodeForces 803 C】Maximal GCD(GCD+思维)

    You are given positive integer number n. You should create such strictly increasingsequence of k pos ...

  4. Codeforces Round #651 (Div. 2) A. Maximum GCD (思维)

    题意:在\(1\)~\(n\)中找两个不相等的数使得他们的\(gcd\)最大. 题解:水题,如果\(n\)是偶数,那么一定取\(n\)和\(n/2\),\(n\)是奇数的话,取\(n-1\)和\((n ...

  5. Wolf and Rabbit(gcd)

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

  6. HDU 1222 Wolf and Rabbit(gcd)

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

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

  8. Maximal GCD CodeForces - 803C (数论+思维优化)

    C. Maximal GCD time limit per test 1 second memory limit per test 256 megabytes input standard input ...

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

随机推荐

  1. [python学习笔记] 开篇

    今天开始学习markdown,立贴为证. 平均一天一小时.两个月先学完基础. 所有的帖子只为了学习记录,有不对的请提出,轻吐槽

  2. call()和apply()的作用

    call( )和apply( )都是为了改变某个函数运行时的上下文而存在的.换句话说是改变函数体内部this的指向 他们的区别就是call()方法接受的是若干个参数的列表,而apply()方法接受的是 ...

  3. Excel的实用函数

    在介绍Excel函数前先说明两个概念:公式和函数. 公式:由用户自行设计对工作表进行计算和处理的计算式,以等号"="开始,其内部可以包括函数.引用.运算符和常量. 函数:即是预先定 ...

  4. Linux学习——shell编程之运算符

    shell编程之运算符 一:shell中常见算术运算符号和优先级 二:算术运算符 Shell 变量:是弱类型!不能进行加减乘除!比较麻烦! 例子 :shell变量弱类型 a=11 b=22 echo ...

  5. 在分布式数据库中CAP原理CAP+BASE

    本篇博文的内容均来源于网络,本人只是整理,仅供学习! 一.关系型数据库 关系型数据库遵循ACID规则 事务在英文中是transaction,和现实世界中的交易很类似,它有如下四个特性: 1.A (At ...

  6. Struts2和SpringMVC的区别

    简单谈一下Struts2和SpringMVC的区别,文章有所引用知乎所对应的答案数据,和所查看的其余资料数据,进行一个简单的汇总,后续查看时使用: 知乎解释链接为:https://www.zhihu. ...

  7. FPGA IN 金融领域

    何为金融: 金融指货币的发行.流通和回笼,贷款的发放和收回,存款的存入和提取,汇兑的往来等经济活动.金融(FIN)就是对现有资源进行重新整合之后,实现价值和利润的等效流通. 金融主要包括银行.证券.基 ...

  8. 单独创建一个Android Test Project 时junit 的配置和使用

    现在的集成ADT后Eclipse都可以直接创建Android Test Project 如图所示: 命名后选择你要测试的单元程序,比如我自己准备测试sms,便可以如图所示那样选择 本人新建的测试工程为 ...

  9. java Web Servlet学习笔记-1 HttpServletQequest对象的学习

     HttpServletQequest对象的学习 HttpServletRequest HttpServletRequest对象代表客户端的请求,当客户端通过HTTP协议访问服务器时,HTTP请求 ...

  10. JavaScript设计模式--简单工厂模式

    一,介绍 工厂模式创建对象(视为工厂里的产品)时无需指定创建对象的具体类. 工厂模式定义一个用于创建对象的接口,这个接口由子类决定实例化哪一个类.该模式使一个类的实例化延迟到了子类.而子类可以重写接口 ...