Guest User

Untitled

a guest
Oct 22nd, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.00 KB | None | 0 0
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <sstream>
  4. #include <queue>
  5. #include <deque>
  6. #include <stack>
  7. #include <map>
  8. #include <vector>
  9. #include <string>
  10. #include <set>
  11. #include <cstdio>
  12. #include <cmath>
  13. #include <ctime>
  14. #include <cstdlib>
  15. #include <cstring>
  16.  
  17. #define sz(a) (int)a.size()
  18. #define all(a) a.begin(), a.end()
  19. #define rall(a) a.rbegin(), a.rend()
  20. #define llong long long
  21. #define zero(a) fabs(a) < 1e-9
  22. #define resz(a, n) a.clear(), a.resize(n)
  23. #define same(a, n) memset(a, n, sizeof(a))
  24. #define make(a, b) make_pair(a, b)
  25.  
  26. using namespace std;
  27.  
  28. const int BOUND = 100000;
  29.  
  30. llong a, b, c;
  31. set< llong > s;
  32.  
  33. int main() {
  34.     cin >> a >> b >> c;
  35.     for (int i = 0; i < 20; i++) {
  36.         llong cur = 1;
  37.         for (int j = 0; j <= 2000000; j++) {
  38.             if (s.find(cur) != s.end()) {
  39.                 printf("%d\n", j);
  40.                 return 0;
  41.             }
  42.             if (j >= i * BOUND && j < (i + 1) * BOUND)
  43.                 s.insert(cur);
  44.             cur = (a * cur + (cur % b)) % c;
  45.         }
  46.         s.clear();
  47.     }
  48.     printf("-1\n");
  49.     return 0;
  50. }
Add Comment
Please, Sign In to add comment