Project Euler #30: Digit Nth powers

  • + 0 comments
    N = int(input())
    c = []
    for i in range(2, 10000000):
        cnt = 0
        for j in str(i):
            cnt += int(j) ** N
        if cnt == i:
            c.append(cnt)
    print(c)
    

    if you want to check for all numbers you can check the numbers in the list then you could simply check their sum for any N value. Just change the line "Print(c)" to print(sum(c)) Be sure to check this in your own ide as here it would give a TLE