forked from nayuki/Project-Euler-solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathp030.py
More file actions
27 lines (20 loc) · 683 Bytes
/
p030.py
File metadata and controls
27 lines (20 loc) · 683 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
#
# Solution to Project Euler problem 30
# Copyright (c) Project Nayuki. All rights reserved.
#
# https://www.nayuki.io/page/project-euler-solutions
# https://github.com/nayuki/Project-Euler-solutions
#
import sys
if sys.version_info.major == 2:
range = xrange
def compute():
# As stated in the problem, 1 = 1^5 is excluded.
# If a number has at least n >= 7 digits, then even if every digit is 9,
# n * 9^5 is still less than the number (which is at least 10^n).
ans = sum(i for i in range(2, 1000000) if i == fifth_power_digit_sum(i))
return str(ans)
def fifth_power_digit_sum(n):
return sum(int(c)**5 for c in str(n))
if __name__ == "__main__":
print(compute())