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.

# Project Euler #29: Distinct powers

# Project Euler #29: Distinct powers

+ 4 comments How is this easy problem ???!!!!

+ 0 comments n=int(input()) lis=set() for a in range(2,n+1): for b in range(2,n+1): lis.add(a**b) print(len(lis))

never try this

+ 1 comment Wrong answer for the last 3 cases and I have no idea why... I get 9981236306 for n=100000

Edit: My solution worked but it took to much memory (about 600MB for n=100000 [Limit is 512MB]) I noticed it after tc18 got a runtime error randomly

I optimized the code and all testcases were accepted

+ 0 comments Well this problem was hell on earth to pass all the cases.

HINT: When can a number have coinciding powers with other numbers?

If a number can have coinciding numbers with other numbers do we need to compute the power or can we a get a shortcut through the exponent?

If a number cannot have coinciding powers with another number, how many distinct powers does this number provide?

+ 1 comment only can't pass the 10th,wa =.=

Load more conversations

Sort 37 Discussions, By:

Please Login in order to post a comment