Project Euler #29: Distinct powers

Sort by

recency

|

47 Discussions

|

  • + 0 comments
    #python
    n=int(input())
    dump=set()
    count=0
    for x in range(2, n+1):
        if x not in dump:
            res=set()
            y=2
            while x**y <=n:
                dump.add(x**y)
                for m in range(2*y, y*(n+1), y):
                    if m>n:
                        res.add(m)
                y+=1
            count+=len(res)+n-1
    print(count)
    
  • + 0 comments
    # My Third attempt was succeded
    # My First Attempt
    
    L = []
    n = int(input(""))
    if n >= 2 and n <= 10**5:
        for i in range(2, n+1):
            for j in range(2, n+1):
                k = i**j
                if k not in L:
                    L.append(k)
                else:
                    pass
        print(len(L))
    else:
        pass
    # Failed
    
    # My Second Attempt
    
    N = int(input())
    L = [True] * (N+1)
    res = 0
    for i in range(2, N+1):
        if L[i]:
            power = 2
            res = []
            while i**power <= N:
                L[i**power] = False
                res += [n for n in range(2*power, N * power+1, power) if n>N]
                power+=1
            res += len(set(res))+(N-1)
            
    print(res)
    # Failed
    
    # My Final Attempt
    
    def dist_term(n: int) -> int:
        count = 0
        test = [0]*(n+1)
        for i in range(2, n+1):
            if test[i]: continue;
            combined = set()
            po = 2
            while (i**po <= n):
                test[i**po] = True
                s = set([j*po for j in range(2, n+1) if j*po > n])
                combined.update(s)
                po += 1
            count += len(combined) + n-1
        return count
                
    print(dist_term(int(input())))
    
  • + 1 comment

    include

    include

    include

    include

    include

    include

    using namespace std;

    int main() { set terms; long n; cin>>n; for(long a = 2; a <= n; a++){ for(long b = 2; b <= n; b++){ long result = pow(a, b); terms.insert(result); } } long count=0; for(long term : terms){ count++; } cout<

    Can anyone explain what's wrong in my code? Only sample test case 0 successfully ran, and all remaining test cases were unsuccessful."

  • + 1 comment
    L=[]
    N=int(input(""))
    if N>=2 and N<=10**5:
        for a in range(2,N+1):
            for b in range(2,N+1):
                c=a**b
                if c not in L:
                    L.append(c)
                else:
                    pass
        print(len(L))
    else:
        pass
    
  • + 0 comments

    I cannot able to understand these problem