Advertisement
Guest User

Untitled

a guest
Dec 13th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <iterator>
  5. #include <map>
  6.  
  7. using namespace std;
  8.  
  9. int main()
  10. {
  11. long long a;
  12. cin >> a;
  13. long long x;
  14. cin >> x;
  15. long long y;
  16. cin >> y;
  17. long long m;
  18. cin >> m;
  19.  
  20. map<int, int> mymap;
  21. int pos = 1;
  22. mymap[a] = pos;
  23. pos++;
  24. while(true) {
  25. a = (x * a + y) % m;
  26. if(mymap[a] != 0) break;
  27. else mymap[a] = pos;
  28. pos++;
  29. }
  30.  
  31. auto iter = mymap.find(a);
  32.  
  33. cout << iter->first << " " << iter->second << endl;
  34.  
  35. int it = iter->second - 1;
  36.  
  37. cout << mymap.size() - it << " " << it;
  38.  
  39. return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement