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.
below code in python passed 1st sample test case but failed hidden test case, could anyone help:
mport sys
def factor(n):
l=[]
for i in range(2,n+1):
if n%i==0:
l.append(i)
for j in l:
for k in range(2, j):
if (j % k) != 0:
continue
else: l.remove(j)
break
#print(j,k)
#print(l)
l.sort(reverse=True)
return(l[0])
t = int(input().strip())
for a0 in range(t):
n = int(input().strip())
print(factor(n))
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Project Euler #3: Largest prime factor
You are viewing a single comment's thread. Return to all comments →
below code in python passed 1st sample test case but failed hidden test case, could anyone help:
mport sys def factor(n): l=[] for i in range(2,n+1): if n%i==0: l.append(i) for j in l: for k in range(2, j): if (j % k) != 0: continue else: l.remove(j) break #print(j,k) #print(l) l.sort(reverse=True) return(l[0])
t = int(input().strip()) for a0 in range(t): n = int(input().strip()) print(factor(n))