采用一个长度为mod的数组来标记0到mod-1是否已经全部在余数中出现过。
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int step,mod,seed,i,choice;
while(cin>>step>>mod)
{
int *s=new int[mod];
for(i=0;i<mod;i++)
s[i]=0;
seed=0,choice=1;
for(i=0;i<mod;i++)
{
seed=(seed+step)%mod;
s[seed]=1;
}
for(i=0;i<mod;i++)
if(s[i]==0)
{
choice=0;
break;
}
cout<<setw(10)<<right<<step<<setw(10)<<right<<mod<<" ";
if(choice)
cout<<"Good Choice"<<endl<<endl;
else
cout<<"Bad Choice"<<endl<<endl;
delete[] s;
}
return 0;
}