Skip to content

Commit ceef603

Browse files
authored
Create main.cpp
1 parent f5f35b9 commit ceef603

File tree

1 file changed

+28
-0
lines changed
  • 07 - Other Concepts/08 - Bit Array

1 file changed

+28
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#include <iostream>
2+
#include <algorithm>
3+
#include <unordered_set>
4+
using namespace std;
5+
6+
7+
int main() {
8+
int N, S, P, Q;
9+
int mod = (1 << 31);
10+
11+
12+
int tortoise = S % mod;
13+
int here = tortoise;
14+
15+
int count = 0;
16+
17+
while(count < N){
18+
count++;
19+
tortoise = (tortoise * P + Q) % mod;
20+
21+
here = (here * P + Q) % mod;
22+
here = (here * P + Q) % mod;
23+
24+
if(here == tortoise) break;
25+
}
26+
cout<< count;
27+
return 0;
28+
}

0 commit comments

Comments
 (0)