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.
You can still use brute-force. Just do some experiments to determine lower and upper limit for i, then you will pass all cases.
defDigit_Nth_Powers(n,lower,upper):sumList=0foriinrange(lower,upper):digits=list(map(int,str(i)))tempSum=0forjindigits:tempSum+=j**nifi==tempSum:sumList+=ireturnsumListif__name__=='__main__':n=int(input())# Lower and upper limit is determined by experiments for faster code executionifn==3:lower,upper=[1*(10**2),1*(10**3)]elifn==4:lower,upper=[1*(10**3),1*(10**4)]elifn==5:lower,upper=[2*(10**3),2*(10**5)]elifn==6:lower,upper=[1*(10**5),6*(10**5)]sumList=Digit_Nth_Powers(n,lower,upper)print(sumList)
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Project Euler #30: Digit Nth powers
You are viewing a single comment's thread. Return to all comments →
You can still use brute-force. Just do some experiments to determine lower and upper limit for i, then you will pass all cases.