a53

xorsum

a53
Jun 22nd, 2020
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. #include <ctype.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4.  
  5. #pragma GCC target ("avx2")
  6. #pragma GCC optimization ("O3")
  7. #pragma GCC optimization ("unroll-loops")
  8.  
  9. #ifdef __unix__
  10. #define getchar getchar_unlocked
  11. #define putchar putchar_unlocked
  12. #endif // __unix__
  13.  
  14. long long read () {
  15. int ch;
  16. while (!isdigit(ch=getchar()));
  17.  
  18. long long ans = 0ll;
  19. do
  20. ans = (ans << 3ll) + (ans << 1ll) + ch - '0';
  21. while (isdigit(ch=getchar()));
  22.  
  23. return ans;
  24. }
  25.  
  26. int print (long long a) {
  27. if (a) {
  28. print(a/10ll);
  29. putchar(a%10ll + '0');
  30. }
  31. return 0;
  32. }
  33.  
  34. static inline long long ori (long long a, long long b, long long mod) {
  35. long long ans = 0ll;
  36. while (b) {
  37. if (b & 1ll) {
  38. ans += a;
  39. if (ans >= mod)
  40. ans -= mod;
  41. }
  42. a <<= 1ll;
  43. if (a >= mod)
  44. a -= mod;
  45. b >>= 1ll;
  46. }
  47. return ans;
  48. }
  49.  
  50. int c[63][2];
  51. int main (void) {
  52. int n = (int)read();
  53. long long x, y, z, t;
  54.  
  55. x=read(), y=read(), z=read(), t=read();
  56. x%=z;
  57. y%=z;
  58.  
  59. long long ans = 0ll, v = 0ll;
  60. int i, j;
  61.  
  62. for (i=0; i<n; ++i) {
  63. v = ori(v, x, z) + y;
  64. v %= z;
  65. for (j=0; j<63; ++j)
  66. ++c[j][v & (1ll << j) ? 1 : 0];
  67. }
  68.  
  69. for (i=0; i<63; ++i) {
  70. ans += ori(ori(c[i][0], c[i][1], t), (1ll << i) % t, t);
  71. ans %= t;
  72. }
  73. print(ans);
  74. return 0;
  75. }
Add Comment
Please, Sign In to add comment