Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <ctype.h>
- #include <stdio.h>
- #include <stdlib.h>
- #pragma GCC target ("avx2")
- #pragma GCC optimization ("O3")
- #pragma GCC optimization ("unroll-loops")
- #ifdef __unix__
- #define getchar getchar_unlocked
- #define putchar putchar_unlocked
- #endif // __unix__
- long long read () {
- int ch;
- while (!isdigit(ch=getchar()));
- long long ans = 0ll;
- do
- ans = (ans << 3ll) + (ans << 1ll) + ch - '0';
- while (isdigit(ch=getchar()));
- return ans;
- }
- int print (long long a) {
- if (a) {
- print(a/10ll);
- putchar(a%10ll + '0');
- }
- return 0;
- }
- static inline long long ori (long long a, long long b, long long mod) {
- long long ans = 0ll;
- while (b) {
- if (b & 1ll) {
- ans += a;
- if (ans >= mod)
- ans -= mod;
- }
- a <<= 1ll;
- if (a >= mod)
- a -= mod;
- b >>= 1ll;
- }
- return ans;
- }
- int c[63][2];
- int main (void) {
- int n = (int)read();
- long long x, y, z, t;
- x=read(), y=read(), z=read(), t=read();
- x%=z;
- y%=z;
- long long ans = 0ll, v = 0ll;
- int i, j;
- for (i=0; i<n; ++i) {
- v = ori(v, x, z) + y;
- v %= z;
- for (j=0; j<63; ++j)
- ++c[j][v & (1ll << j) ? 1 : 0];
- }
- for (i=0; i<63; ++i) {
- ans += ori(ori(c[i][0], c[i][1], t), (1ll << i) % t, t);
- ans %= t;
- }
- print(ans);
- return 0;
- }
Add Comment
Please, Sign In to add comment