小明传球
2016-04-16 11:55
225 查看
小明传球
Time Limit : 3000/1000ms (Java/Other) Memory Limit : 65535/32768K (Java/Other)
Total Submission(s) : 42 Accepted Submission(s) : 13
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
n个人围成一个圈传球。小明站在第1个位置,刚开始球在小明手上。现在每次传球都是把球交给球当前所在的位置的顺时针第k个人,不经过中间人的手。问:当小球第一次回到小明手上时,除了小明拿了2次球,其他人是否恰好拿了1次球。
Input
多组输入,每行两个整数,表示n, k(n, k <= 1000 000 000)
Output
如果可以,输出YES,否则输出NO
Sample Input
5 3 8 6
Sample Output
YES NO
#include<iostream> #include<stdio.h> #include<cmath> #include<algorithm> #include<string> #include<string.h> using namespace std; int gcd(int x,int y) { return y?gcd(y,x%y):x; } int main() { int n,k; while(cin>>n>>k) { if(gcd(n,k)==1) cout<<"YES"<<endl; else cout<<"NO"<<endl; } return 0; }
#include<iostream> #include<stdio.h> #include<cmath> #include<algorithm> #include<string> #include<string.h> using namespace std; int f(int n,int m) { int r; if(n>m)swap(n,m); while(n!=0) { r=m%n; m=n; n=r; } return m; } int main() { int n,k; while(cin>>n>>k) { if(f(n,k)==1) cout<<"YES"<<endl; else cout<<"NO"<<endl; } return 0; }
相关文章推荐
- 1、cas4.0 单点登录 之 https证书
- linux 用户环境变量介绍
- ios多线程操作(八)—— GCD调度组
- wordpress发表文章之后查看显示404
- PPT1
- Android中自定义checkbox样式
- Code Forces 645A Amity Assessment
- 五步搞定Android开发环境部署——非常详细的Android开发环境搭建教程
- 第一类第二类斯特林数总结
- Light OJ 1420 - Subsequences forming Strings (DP)
- ios多线程操作(七)—— GCD延迟操作与一次性代码
- Code Forces 645A Amity Assessment
- ti processor sdk linux am335x evm /bin/setup-uboot-env.sh hacking
- Hibernate环境配置
- Linux的lshw命令
- 如何提高UDP的可靠性
- ios多线程操作(六)—— GCD全局队列与主队列
- 企业IT架构介绍
- 年度总结(14)
- 配置IDEA Scala环境