You are viewing a single comment's thread. Return to all comments →
Only one testcase didnot get pass.can anyone tell how to reduce time complexity in this code.
def isprime(n): if(n<=1): return 0 for i in range(2,int(sqrt(n))+1): if(n%i==0): return 0 break return 1 t = int(input().strip()) for t_itr in range(t): n = int(input().strip()) if(isprime(n)): print(n) else: for i in range(n//2,0,-1): if(n%i==0 and isprime(i)): print(i) break
`
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 →
Only one testcase didnot get pass.can anyone tell how to reduce time complexity in this code.
`