coding utf-8 def read file task2-1 txt input str read strip input spli

 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
# -*- coding: utf-8 -*-
def read():
f = file('task2-1.txt')
input = str(f.read()).strip()
a, b, x, k, m = input.split(' ')
return int(a), int(b), int(x), int(k), int(m)
def lgc_next(a, b, m, x):
return (a * x + b) % m
def main():
results = []
a, b, x, k, m = read()
if k > m:
k = k % m + m
for i in xrange(k - 1):
x = lgc_next(a, b, m, x)
results.append(x)
for i in xrange(4):
x = lgc_next(a, b, m, x)
results.append(x)
for result in results:
print result
if __name__ == '__main__':
main()