ACM--steps--2.2.4--求最大公约数
来源:互联网 发布:淘宝网吸顶灯 编辑:程序博客网 时间:2024/06/08 10:36
Wolf and Rabbit
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 2020 Accepted Submission(s): 1145Problem 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.
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
21 22 2
Sample Output
NOYES
Author
weigang Lee
一开始想到Joseph。。。后来看了看,原来就是最大公约数的问题。
一开始想到Joseph。。。后来看了看,原来就是最大公约数的问题。
#include<iostream>using namespace std;bool dyx(int m,int n){ if(m>n) { m=m^n; n=m^n; m=m^n; } while(n%m) { int wyx=n%m; n=m; m=wyx; } return m==1?false:true;}int main(){ int T; cin>>T; while(T--) { int m,n; cin>>m>>n; if(dyx(m,n)) cout<<"YES"<<endl; else cout<<"NO"<<endl; } return 0;}<span style="color:#66ff99;"></span>
0 0
- ACM--steps--2.2.4--求最大公约数
- hdu acm steps 2.2.4
- ACM--steps--2.2.1--求fibonacci数列的前四位
- hdu ACM Steps 2.2
- ACM steps 1.1.4
- ACM大数之间求最大公约数
- ACM 二进制求最大公约数 HDU5050
- ACM--steps-2.1.8--求最高位
- hdu acm steps 2.2.1
- hdu acm steps 2.2.2
- hdu acm steps 2.2.3
- hdu acm steps 2.2.5
- hdu acm steps 2.2.6
- hdu acm steps 2.2.7
- hdu acm steps 2.2.8
- ACM--steps--2.2.2--Joseph
- ACM--steps--2.2.5--模拟
- hdu acm steps 1.3.4
- (五)Spring核心框架 - IOC与DI的理论本质
- 注胶隔热型材加工过程中常见问题处理三
- Unity3D学习日志第二天
- 最值得你学习的编程语言!
- android Draw Rect 坐标图示
- ACM--steps--2.2.4--求最大公约数
- UVALive - 3027 - Corporative Network (并查集!!)
- IntelliJ IDEA 14 注册码
- 正向代理与反向代理的区别【Nginx读书笔记】
- css性能及规范要点
- TI C6000系列DSP的流水线介绍和软件流水优化
- java的Serialization 机制
- Java关键字(key)
- 你最深爱的编程语言其实很烂