fork download
  1. #include <vector>
  2. #include <iostream>
  3. #include <iomanip>
  4. #include <ctime>
  5.  
  6. using namespace std;
  7.  
  8. int lcg(int seed = -1)
  9. {
  10. static int result = 0;
  11. if (seed >= 0) result = seed;
  12. int m = 0xfffffff;
  13. int c = 1;
  14. int a = 22695477;
  15. result = (a * result + c) % m;
  16. if (result < 0) result = -result;
  17. return result;
  18. }
  19.  
  20. int main(int argc, char * argv[])
  21. {
  22. for(int i = 0; i < 20; i+=2)
  23. {
  24. lcg(time(0)+i);
  25.  
  26. int M = 0, C = 0;
  27. vector<bool> v(0xfffffff);
  28. for(;;)
  29. {
  30. int x = lcg();
  31. if (v[x]) break;
  32. ++C;
  33. if (M < x) M = x;
  34. v[x] = true;
  35. }
  36. cout << C << " " << M << endl;
  37. }
  38. }
  39.  
Success #stdin #stdout 0.05s 36128KB
stdin
Standard input is empty
stdout
14507  268396414
16711  268388908
18069  268404571
6519  268345058
14956  268388908
8737  268371468
16026  268391924
18508  268388908
12865  268409764
8493  268371468