Skip to content

Commit 086b8a5

Browse files
committed
172b solved
1 parent dc52619 commit 086b8a5

File tree

11 files changed

+165
-0
lines changed

11 files changed

+165
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"mainSolution": {
3+
"value": "/Users/dipta007/my-world/gdrive/Programming/Contest-LIFE/@SITES/acmx/Codeforces - Croc Champ 2012 - Qualification Round/B. Pseudorandom Sequence Period/template.py"
4+
},
5+
"bruteSolution": {},
6+
"generator": {},
7+
"checker": {},
8+
"companionConfig": {
9+
"value": {
10+
"name": "B. Pseudorandom Sequence Period",
11+
"group": "Codeforces - Croc Champ 2012 - Qualification Round",
12+
"url": "https://codeforces.com/problemset/problem/172/B",
13+
"memoryLimit": 256,
14+
"timeLimit": 2000
15+
}
16+
}
17+
}
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
""" Python 3 compatibility tools. """
2+
from __future__ import division, print_function
3+
import itertools
4+
import sys
5+
import os
6+
from io import BytesIO, IOBase
7+
8+
9+
if sys.version_info[0] < 3:
10+
input = raw_input
11+
range = xrange
12+
13+
filter = itertools.ifilter
14+
map = itertools.imap
15+
zip = itertools.izip
16+
17+
18+
def is_it_local():
19+
script_dir = str(os.getcwd()).split('/')
20+
username = "dipta007"
21+
return username in script_dir
22+
23+
24+
def READ(fileName):
25+
if is_it_local():
26+
sys.stdin = open(f'./{fileName}', 'r')
27+
28+
# region fastio
29+
BUFSIZE = 8192
30+
31+
class FastIO(IOBase):
32+
newlines = 0
33+
34+
def __init__(self, file):
35+
self._fd = file.fileno()
36+
self.buffer = BytesIO()
37+
self.writable = "x" in file.mode or "r" not in file.mode
38+
self.write = self.buffer.write if self.writable else None
39+
40+
def read(self):
41+
while True:
42+
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
43+
if not b:
44+
break
45+
ptr = self.buffer.tell()
46+
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
47+
self.newlines = 0
48+
return self.buffer.read()
49+
50+
def readline(self):
51+
while self.newlines == 0:
52+
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
53+
self.newlines = b.count(b"\n") + (not b)
54+
ptr = self.buffer.tell()
55+
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
56+
self.newlines -= 1
57+
return self.buffer.readline()
58+
59+
def flush(self):
60+
if self.writable:
61+
os.write(self._fd, self.buffer.getvalue())
62+
self.buffer.truncate(0), self.buffer.seek(0)
63+
64+
65+
class IOWrapper(IOBase):
66+
def __init__(self, file):
67+
self.buffer = FastIO(file)
68+
self.flush = self.buffer.flush
69+
self.writable = self.buffer.writable
70+
self.write = lambda s: self.buffer.write(s.encode("ascii"))
71+
self.read = lambda: self.buffer.read().decode("ascii")
72+
self.readline = lambda: self.buffer.readline().decode("ascii")
73+
74+
if not is_it_local():
75+
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
76+
input = lambda: sys.stdin.readline().rstrip("\r\n")
77+
78+
# endregion
79+
80+
81+
def input1(type=int):
82+
return type(input())
83+
84+
85+
def input2(type=int):
86+
[a, b] = list(map(type, input().split()))
87+
return a, b
88+
89+
90+
def input3(type=int):
91+
[a, b, c] = list(map(type, input().split()))
92+
return a, b, c
93+
94+
95+
def input_array(type=int):
96+
return list(map(type, input().split()))
97+
98+
99+
def input_string():
100+
s = input()
101+
return list(s)
102+
103+
if is_it_local():
104+
def debug(*args):
105+
st = ""
106+
for arg in args:
107+
st += f"{arg} "
108+
print(st)
109+
else:
110+
def debug(*args):
111+
pass
112+
113+
##############################################################
114+
115+
def main():
116+
[a, b, m, r0] = input_array()
117+
118+
a %= m
119+
b %= m
120+
r0 %= m
121+
122+
mp = {}
123+
mp[r0] = 0
124+
125+
step = 1
126+
while True:
127+
r = (a * r0 + b)%m
128+
# print(r)
129+
if r in mp:
130+
print(step - mp[r])
131+
break
132+
mp[r] = step
133+
step += 1
134+
r0 = r
135+
pass
136+
137+
if __name__ == '__main__':
138+
# READ('in.txt')
139+
main()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2 6 12 11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2 3 5 1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3 6 81 9

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy