-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhr_bit_array.cpp
More file actions
31 lines (30 loc) · 806 Bytes
/
Copy pathhr_bit_array.cpp
File metadata and controls
31 lines (30 loc) · 806 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
constexpr unsigned int p2t31 = (1 << 31);
int main() {
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
unsigned int n, s, p, q; // (s, p, q) mod 2^31 = (s, p, q)
cin >> n >> s >> p >> q;
if (n == 0) {
cout << "0\n";
return 0;
}
unsigned int curr_a = s, apm;
vector<bool> ut(p2t31);
ut[curr_a] = true;
int u = 1;
for (int i = 1; i < n; ++i) {
apm = (curr_a * p) & (0x7FFFFFFF); // = a * p mod 2^31
curr_a = (apm + q) & (0x7FFFFFFF); // = (apm + q) mod 2^31
if (not ut[curr_a]) {
++u;
ut[curr_a] = true;
}
}
cout << u << "\n";
return 0;
}