-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblem56.py
More file actions
67 lines (41 loc) · 1.23 KB
/
Copy pathproblem56.py
File metadata and controls
67 lines (41 loc) · 1.23 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import time
import math
from mymodule import calculate_time
from mymodule import is_prime
from mymodule import num_digit
#########################################################################3
## A^B mod C = ( (A mod C)^B ) mod C
## (A * B) mod C = (A mod C * B mod C) mod C
def power_mode(a, b, c): # return a^b mode c
modval = a%c
temp = modval
for i in range(1, b):
temp = (temp * modval) % c
return temp
def nth_digit(a,b, n): #a^b
return int((power_mode(a, b, 10**(n)) - power_mode(a, b, 10**(n-1)))/10**(n-1))
def sum_digits(a, b):
digits = int(b*math.log10(a)) + 1
sdigit = 0
for i in range(1, digits + 1):
sdigit += nth_digit(a,b,i)
return sdigit
def test():
print(52**2)
print(nth_digit(52,2,4))
print(sum_digits(52,2))
return
#########################################################################3
@calculate_time
def main():
max56 = 0
for a in range(1, 100):
for b in range(1, 100):
temp = sum_digits(a, b)
if max56 < temp:
max56 = temp
print(max56)
return 0
if __name__ == "__main__":
main()
# test()