We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
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_)
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
An unexpected error occurred. Please try reloading the page. If problem persists, please contact support@hackerrank.com
Project Euler #30: Digit Nth powers
You are viewing a single comment's thread. Return to all 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_)