Uniform Generator

http://acm.hdu.edu.cn/showproblem.php?pid=1014

集合判重简单明了

#include 
#include 
using namespace std;
set<int> S;
int main()
{
    int s,m;
    while(scanf("%d%d",&s,&m)!=EOF){
        S.clear();
        int x=s%m;
        S.insert(x);
        while(1){
            x=(x+s)%m;
            if(S.count(x)==1)break;
            else S.insert(x);
        }
        int n=S.size();
        if(n!=m)printf("%10d%10d    Bad Choice\n",s,m);
        else printf("%10d%10d    Good Choice\n",s,m);
        printf("\n");
    }
    return 0;
}

你可能感兴趣的:(ACM)