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

+ 0 comments Nice challenge. For those who are struggling like I did. I counted the maximum Exponent number and then checked if b can be combined by any number below this max exponent. For example 8 = 2^3 so 8^b can be combined by 2^1*c or 2^2*d.

int findMaxExponent(int num) { int root = sqrt(num); if(root == 1) return 1; for(int i = 2; i <= root; i++) { int cached_num = num; int expo_count = 1; while(cached_num % i == 0) { expo_count++; cached_num /= i; if(cached_num == i) { return expo_count; } } } return 1; }

+ 0 comments Easy, really? Two whole days and I haven't managed to find a O(1) solution. Used double memorization and some optimization. Final timing for N=100000 is 0.2 seconds.

+ 0 comments Blimey, that was pretty tough. No way an easy problem.

+ 2 comments can anybody help me? what's wrong with the code

n = int(input()) l = [] for i in range(2, n+1): for j in range(2,n+1): l.append(i**j) print(len(list(dict.fromkeys(l))))

+ 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

Load more conversations

Sort 39 Discussions, By:

Please Login in order to post a comment