UVA - 408 Uniform Generator

来源:互联网 发布:mac优酷怎么缓存 编辑:程序博客网 时间:2024/05/22 15:13

http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=19090

以前就做过这题,当时也是用枚举的,但是还是因为格式错了几次。

#include<stdio.h>#include<string.h>#define maxn 10000001char f[maxn];int main(){    int n,m,sum,x,y;    while(~scanf("%d%d",&n,&m))    {        sum=1,x=0;        memset(f,0,sizeof(f));        f[0]=1;        while(1)        {            x=(x+n)%m;            if(f[x]) break;            f[x]=1;            sum++;        }        if(sum==m) printf("%10d%10d    Good Choice\n",n,m);        else printf("%10d%10d    Bad Choice\n",n,m);        printf("\n");    }    return 0;}

当然  还可以看出来 可以直接判断两数是否互质,只是还不会证明。

#include<iostream>#include<cstdio>using namespace std;int gcd(int a, int b)    //求最大公约数{    return b? gcd(b, a%b) : a;}int main(){    int s, m;    while(cin >> s >> m)    {        if (gcd(s, m) == 1)            printf("%10d%10d    Good Choice\n\n", s, m);        else            printf("%10d%10d    Bad Choice\n\n", s, m);    }    return 0;}


0 0