-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathbitset-1.cpp
More file actions
37 lines (29 loc) · 754 Bytes
/
Copy pathbitset-1.cpp
File metadata and controls
37 lines (29 loc) · 754 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
32
33
34
35
36
37
// https://www.hackerrank.com/challenges/bitset-1/problem
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <set>
using namespace std;
int main() {
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
unsigned int N, S, P, Q;
unsigned int i, a;
vector<bool> present; // nota: vector<bool> est optimisé
present.resize(0x80000000);
if (scanf("%u %u %u %u", &N, &S, &P, &Q) != 4)
exit(2);
int nb = 0;
i = 0;
a = S % 0x80000000;
do {
if (! present[a]) {
++nb;
present[a] = true;
}
a = (a * P + Q) % 0x80000000;
} while (++i < N);
cout << nb << endl;
return 0;
}