The main topic: give two number, s,m, according to the requirements of the question to calculate the generated random sequence, to determine whether 0~m-1 this M-series, if it is a good choice, otherwise is bad choice.
Algorithm idea;
Use a tag flag[maxn] to record the first 0~m-1 is generated, and NUM record the length of the sequence, the loop to determine whether the current number has been generated before, if there is no mark, no and determine whether NUM is equal to M, if the wait is a good choice, unequal is not a good choice. The output is 10 bytes in S,m, and the string starts out in 25 columns and is left-justified. Empty line after each use case.
The code is as follows:
#include <iostream> #include <iomanip> #include <cstring> #include <algorithm>using namespace Std;const int Maxn=111111;bool Flag[maxn];int main () { int s,m; int seed; while (cin>>s>>m) { int num=0; memset (flag,0,sizeof (flag)); seed=0; while (!flag[seed]) { flag[seed]=true; Seed= (seed+s)%m; num++; } if (num==m) COUT<<RIGHT<<SETW (Ten) <<S<<SETW (Ten) <<m<< " " <<left< < "good Choice" <<endl<<endl; else COUT<<RIGHT<<SETW <<S<<SETW (Ten) <<m<< " <<left<<" Bad Choice "<<endl<<endl; } return 0;}
HDOJ 1014 Simulation