a53

xorsum_Of

a53
Jun 22nd, 2020
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. /// Solutie - Moca Andrei - 100p
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4. typedef long long i64;
  5. inline i64 Multiply(i64 a, i64 b, i64 MOD) {
  6. i64 res(0);
  7. while (b) {
  8. if (b & 1) {
  9. res += a;
  10. if (res >= MOD)
  11. res -= MOD;
  12. }
  13. a += a;
  14. if (a >= MOD)
  15. a -= MOD;
  16. b >>= 1;
  17. }
  18. return res;
  19. }
  20. const int LOG(62);
  21. int freq[LOG][2], n;
  22. i64 res, x, y, z, t, a, p2[LOG];
  23. int main() {
  24. p2[0] = 1;
  25. for (int i = 1; i < LOG; ++i)
  26. p2[i] = p2[i - 1] << 1;
  27. cin >> n >> x >> y >> z >> t;
  28. x %= z, y %= z;
  29. for (int i = 1; i <= n; ++i) {
  30. a = Multiply(a, x, z) + y;
  31. if (a >= z)
  32. a -= z;
  33. for (int bit = 0; bit < LOG; ++bit)
  34. ++freq[bit][!!(a & p2[bit])];
  35. }
  36. for (int bit = 0; bit < LOG; ++bit) {
  37. res += Multiply(Multiply(freq[bit][0], freq[bit][1], t), p2[bit] % t, t);
  38. if (res >= t)
  39. res -= t;
  40. }
  41. cout << res;
  42. return 0;
  43. }
Add Comment
Please, Sign In to add comment