fork download
  1. // Problem 1: Linear Congruential Generator
  2.  
  3. #include <bits/stdc++.h>
  4. using namespace std;
  5.  
  6. int main() {
  7. long long m = 100, a = 17, c = 43, x = 1;
  8. for (int i = 0; i < 10; i++) {
  9. x = (a * x + c) % m;
  10. cout << x << " ";
  11. }
  12. cout << endl;
  13. return 0;
  14. }
  15.  
  16. /*
  17. Q1. Do you see repeating numbers?
  18. = Yes. The sequence eventually repeats because the generator works in a cycle.
  19.  
  20. Q2. How long before it repeats?
  21. = The repeat length (period) depends on m, a, c. For small m like 100,
  22. the cycle comes quickly. Larger m increases the period.
  23. */
  24.  
Success #stdin #stdout 0.01s 5320KB
stdin
Standard input is empty
stdout
60 63 14 81 20 83 54 61 80 3