Project Euler #30: Digit Nth powers

  • + 0 comments

    for n=5, it also has numbers ranging from 1000 to 1000000, so the solution in python will be

    n=int(input().strip()) sum_=0 if n==5: sum_ = sum([i for i in range(10**(n-2), 10**(n+1)) if sum(int(digit)n for digit in str(i)) == i]) print(sum_) else: sum_ = sum([i for i in range(10(n-1), 10**(n)) if sum(int(digit)**n for digit in str(i)) == i]) print(sum_)