小明传球

小明传球

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


 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值