2343: Sing a Song
| Result | TIME Limit | MEMORY Limit | Run Times | AC Times | JUDGE |
|---|---|---|---|---|---|
| | 3s | 16384K | 1186 | 215 | Standard |
N students are playing a game, they sit in a circle and number themselves with 1 to N clockwise. First, the teacher let the student whose number is 1 to sing a song. Then Mth student clockwise sings a song, and go on. + 0 1 what to know whether each student has a chance to sing.Can you help him?
Input
The input file consists several cases. Each case contains two positive integers N and M. (1 <= n, m <=1000)
Hint: Use "scanf" and "printf" to read and write.
Output
If everyone has a chance to sing, print "YES", else "NO";
Sample Input
5 1 4 2
Sample Output
YES NO
Problem Source: +01
This problem is used for contest: 57 190
#include<stdio.h>
int gcd(int u,int v)
{
while(u%v!=0)
{
int t=u%v;
u=v;
v=t;
}
return v;
}
int main()
{
int n,m;
while(scanf("%d%d",&n,&m)==2)
{
if(gcd(n,m)!=1)printf("NO\n");
else printf("YES\n");
}
return 0;
} 这个题目可以用推到的方式解决,如果mn有大于一的共因数那么他们就可以避开与他们相邻的数了。。
82

被折叠的 条评论
为什么被折叠?



