Gornak40

Random

Jan 26th, 2021 (edited)
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.96 KB | None | 0 0
  1. #pragma GCC optimize("Ofast")
  2. #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
  3. #include <bits/stdc++.h>
  4. #include <ext/rope>
  5. #include <ext/pb_ds/assoc_container.hpp>
  6. #define endl '\n'
  7. #define fixstd() ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
  8. #define precision(n) cout.setf(ios::fixed), cout.precision(n)
  9. #define all(arr) arr.begin(), arr.end()
  10. #define rall(arr) arr.rbegin(), arr.rend()
  11. #define sz(arr) int(arr.size())
  12. #define sqr(n) ((n) * (n))
  13. #define print(arr) {for (auto el: arr) cout << el << ' '; cline();}
  14. #define pprint(A) for (auto &x: A) print(x)
  15. #define cprint(A) {for (auto &x: A) cout << x.fi << ',' << x.se << ' '; cline();}
  16. #define read(arr) for (auto &el: arr) cin >> el
  17. #define make_uniq(arr) sort(all(arr)), arr.resize(unique(all(arr)) - arr.begin());
  18. #define inc(arr) for (auto &x: arr) ++x
  19. #define dec(arr) for (auto &x: arr) --x
  20. #define multitest() int _; cin >> _; for (; _; --_)
  21. #define yesno(fl) (fl ? "YES" : "NO")
  22. #define out(n) cout << n << endl, exit(0);
  23. #define write(n) cout << n << endl
  24. #define debug(s, n) cout << s << ": " << n << endl
  25. #define cline() cout << endl
  26. #define pb push_back
  27. #define mp make_pair
  28. #define fi first
  29. #define se second
  30. using namespace std;
  31. using namespace __gnu_cxx;
  32. using namespace __gnu_pbds;
  33. typedef tree<int, null_type, less<int>, rb_tree_tag,
  34. tree_order_statistics_node_update> indexed_set;
  35. typedef long long lint;
  36. typedef long double ld;
  37. typedef string str;
  38. #define int lint
  39. typedef pair<int, int> col;
  40. typedef pair<lint, lint> coll;
  41. typedef pair<ld, ld> cold;
  42. typedef pair<str, str> cols;
  43.  
  44. int A, B, C, D;
  45.  
  46. inline int go(int x0, int x1) {
  47.     return (A * x1 + B * x0 + C) % D;
  48. }
  49.  
  50. int get_p(int x0, int x1) {
  51.     int n;
  52.     for (int i = 0; i < D; ++i) {
  53.         n = go(x0, x1);
  54.         x0 = x1, x1 = n;
  55.     }
  56.     int y0 = x0, y1 = x1;
  57.     n = go(x0, x1);
  58.     x0 = x1, x1 = n;
  59.     int p = 0;
  60.     while (x0 != y0 || x1 != y1) {
  61.         n = go(x0, x1);
  62.         x0 = x1, x1 = n;
  63.         ++p;
  64.     //  cout << x0 << z' ' << x1 << ' ' << x2 << endl;
  65.     }
  66.     return p;
  67. }
  68.  
  69. int get_n(int p, int x0, int x1) {
  70.     int y0 = x0, y1 = x1;
  71.     for (int i = 0; i <= p; ++i) {
  72.         int n = go(y0, y1);
  73.         y0 = y1, y1 = n;
  74.     }
  75.     int i;
  76.     for (i = 0; x0 != y0; ++i) {
  77.         int n = go(x0, x1);
  78.         x0 = x1, x1 = n;
  79.         n = go(y0, y1);
  80.         y0 = y1, y1 = n;
  81.     }
  82.     return i;
  83. }
  84.  
  85. ld get_q(int x0, int x1) {
  86.     vector<int> cnt(20, 0);
  87.     for (int i = 0; i < 400; ++i) {
  88.     //  int g = i / 20;
  89.     //  int left = g * p, right = (g + 1) * p;
  90.         int n = go(x0, x1);
  91.         for (int j = 0; j < 20; ++j) {
  92.             if (j * D <= 20 * n && 20 * n < (j + 1) * D) {
  93.                 ++cnt[j];
  94.                 break;
  95.             }
  96.         }
  97.         x0 = x1, x1 = n;
  98.     }
  99. //  print(cnt);
  100.     int ans = 0;
  101.     for (int i = 0; i < 20; ++i)
  102.         ans += sqr(cnt[i] - 20);
  103.     return (ld)ans / 400;
  104. }
  105.  
  106. signed main() {
  107.     precision(2);
  108.     cin >> A >> B >> C >> D;
  109.     int x0, x1; cin >> x0 >> x1;
  110.     int p = get_p(x0, x1);
  111. //  debug('p', p);
  112.     int n = get_n(p, x0, x1);
  113. //  debug('n', n);
  114.     ld q = get_q(x0, x1);
  115.     cout << ++p << ' ' << n << ' ' << q << endl;
  116. }
Add Comment
Please, Sign In to add comment