Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- const long long mod = 1LL << 32;
- const long long M = (1LL << 31);
- bitset<M> b;
- signed main()
- {
- ios_base::sync_with_stdio(false);
- cin.tie(NULL); cout.tie(NULL);
- int q;
- long long S, A, B;
- cin >> q >> S >> A >> B;
- long long ans = 0;
- for (int i = 1; i <= q; i++)
- {
- long long val = (S >> 1);
- if (S & 1)
- {
- if (b[val] == 0)
- {
- ans += val;
- }
- b[val] = 1;
- }
- else
- {
- if (b[val] == 1)
- {
- ans -= val;
- }
- b[val] = 0;
- }
- S = (A * S + B) % mod;
- }
- cout << ans << "\n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement