-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproblem30.py
39 lines (35 loc) · 919 Bytes
/
problem30.py
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
#Digit fifth powers
power_array = [ x**5 for x in range (0, 10) ]
def get_fifth_power_sum(value):
sum = 0
for x in str(value):
sum += power_array[int(x)]
return int(sum)
def get_fifth_power_sum2(value):
sum = 0
while value > 0:
x = value % 10
sum += power_array[x]
value = int(value / 10)
return int(sum)
if __name__ == "__main__":
import timeit
results = []
x = 1000
start_time = timeit.default_timer()
while(x < 354295):
sum = get_fifth_power_sum(x)
if sum == x:
results.append(x)
x += 1
elif sum > x:
x = (int)((int(x / 10) + 1) * 10)
else:
x += 1
elapsed = timeit.default_timer() - start_time
print("gen time: %s" % elapsed)
sum = 0
for x in results:
sum += x
print(results)
print(sum)