-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblem26.py
More file actions
48 lines (30 loc) · 743 Bytes
/
Copy pathproblem26.py
File metadata and controls
48 lines (30 loc) · 743 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
38
39
40
41
42
43
44
45
46
47
48
import math
def num_digit(n):
return int(math.log10(n)) + 1
def calculate_cycle(p):
## (A * B) mod C = (A mod C * B mod C) mod C
## A^B mod C = ( (A mod C)^B ) mod C
index = 1
while p % 5 == 0:
p = p / 5
while p % 2 == 0:
p = p / 2
if p == 1:
return 0
modval = 10 % p
temp = modval
while True:
if temp == 1:
return index
temp = (temp * modval) % p
index += 1
max_recuring_digit = 0
d_max = 1000
valdict = {0: 0}
d_result = 0
for p in range(2, d_max):
k = calculate_cycle(p)
if max_recuring_digit < k:
max_recuring_digit = k
d_result = p
print(d_result)