Returns the value of 30th digit power sum. >>> solution(2) 512 >>> solution(5) 5832 >>> solution(10) 614656
(n: int = 30)
| 27 | |
| 28 | |
| 29 | def solution(n: int = 30) -> int: |
| 30 | """ |
| 31 | Returns the value of 30th digit power sum. |
| 32 | >>> solution(2) |
| 33 | 512 |
| 34 | >>> solution(5) |
| 35 | 5832 |
| 36 | >>> solution(10) |
| 37 | 614656 |
| 38 | """ |
| 39 | digit_to_powers = [] |
| 40 | for digit in range(2, 100): |
| 41 | for power in range(2, 100): |
| 42 | number = int(math.pow(digit, power)) |
| 43 | if digit == digit_sum(number): |
| 44 | digit_to_powers.append(number) |
| 45 | |
| 46 | digit_to_powers.sort() |
| 47 | return digit_to_powers[n - 1] |
| 48 | |
| 49 | |
| 50 | if __name__ == "__main__": |