UVa 408 Uniform Generator

 1  #include <stdio.h>
 2  #include <stdlib.h>
 3  #include <iostream>
 4  #include <algorithm>
 5  #include <set>
 6  using namespace std;
 7  int step,mod;
 8  bool check()
 9  {
10      int tmp=0;
11      set<int> s;
12      s.insert(tmp);
13      for(int i=0;i<mod-1;i++)
14      {
15          tmp=(tmp+step)%mod;
16          s.insert(tmp);
17      }
18      if(s.size()==mod) return true;
19      else return false;
20  }
21  int main()
22  {
23      while(cin >> step >> mod)
24      {
25          bool flag=false;
26          flag=check();
27          if(flag==true)
28              printf("%10d%10d    %s\n\n",step,mod,"Good Choice");
29          else
30              printf("%10d%10d    %s\n\n",step,mod,"Bad Choice");
31      }
32      return 0;

33  }

留言

這個網誌中的熱門文章

Things a Little Bird Told Me: Confessions of the Creative Mind

UVa 12970 Alcoholic Pilots

UVa 483 Word Scramble