You are viewing a single comment's thread. Return to all comments →
my code is showing timeout error...any minor changes i should make in the algorithm??
def primefactors(n): m=n a=[] while n%2==0: a.append(2) if len(a)==3: return(-1) n=n//2 for i in range(3,(m//2)+1,2): while n%i==0: a.append(i) if len(a)==3: return(-1) n=n//i if len(a)==2: return(m) n=int(input()) for i in range(n): y=int(input()) count=0 for j in range(2,y): if primefactors(j)==j: count=count+1 print(count)
Seems like cookies are disabled on this browser, please enable them to open this website
Project Euler #187: Semiprimes
You are viewing a single comment's thread. Return to all comments →
my code is showing timeout error...any minor changes i should make in the algorithm??