您的位置:首页 > 其它

小明传球

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;
}



                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: