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.
# My Third attempt was succeded# My First AttemptL=[]n=int(input(""))ifn>=2andn<=10**5:foriinrange(2,n+1):forjinrange(2,n+1):k=i**jifknotinL:L.append(k)else:passprint(len(L))else:pass# Failed# My Second AttemptN=int(input())L=[True]*(N+1)res=0foriinrange(2,N+1):ifL[i]:power=2res=[]whilei**power<=N:L[i**power]=Falseres+=[nforninrange(2*power,N*power+1,power)ifn>N]power+=1res+=len(set(res))+(N-1)print(res)# Failed# My Final Attemptdefdist_term(n:int)->int:count=0test=[0]*(n+1)foriinrange(2,n+1):iftest[i]:continue;combined=set()po=2while(i**po<=n):test[i**po]=Trues=set([j*poforjinrange(2,n+1)ifj*po>n])combined.update(s)po+=1count+=len(combined)+n-1returncountprint(dist_term(int(input())))
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Project Euler #29: Distinct powers
You are viewing a single comment's thread. Return to all comments →