Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define set _set
- const int maxn = 100000000;
- char p[maxn / 16 + 1];
- void set(int x) {
- x >>= 1;
- p[x / 8] |= '\1' << (x % 8);
- }
- bool get(int x) {
- x >>= 1;
- return !((p[x / 8] >> (x % 8)) & 1);
- }
- void build() {
- for (int i = 3; i < maxn; i += 2) {
- if (!get(i))
- continue;
- for (int j = i + (i << 1); j < maxn; j += (i << 1)) {
- set(j);
- }
- }
- }
- bool f(int x) {
- if (x == 2) return true;
- if ((x & 1) == 0) return false;
- return get(x);
- }
- void solve() {
- int a, b, r, n, q;
- cin >> a >> r >> b >> n >> q;
- long long ans = 0;
- while (q--) {
- r = ((1LL * a * r) + b) % n;
- ans += f(r);
- }
- cout << ans << '\n';
- }
- signed main() {
- ios::sync_with_stdio(0); cin.tie(0);
- build();
- solve();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement