Created
October 20, 2023 20:18
-
-
Save michaelsoltys/d05d8a386eb9f55716019e112f987ee9 to your computer and use it in GitHub Desktop.
Sum of powers of digits
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
# replace 999999999 with upper limit of your choice | |
for i in range(1, 999999999): | |
i_as_string = str(i) | |
i_as_list = [] | |
j = 1 | |
output = 0 | |
for digits in i_as_string: | |
output += pow(int(digits),j) | |
j += 1 | |
if output == i: | |
j = 0 | |
for digits in i_as_string: | |
j += 1 | |
print(digits, "^", j, sep = "", end = "") | |
if j < len(i_as_string): | |
print(" + ", end = "") | |
print (" = ", i) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment