0
Why its taking much time? Is it a problem in program?
I have written code about finding the largest prime factor of a number. It is ok and giving me the right answer. But when I giving it a large number like 100M its taking time and time but don't giving me the output. Is there any problem in my code or just it is taking time cause it is a big number?? If it is then why it is not giving me an answer? I have waited along. Code link , https://code.sololearn.com/cks5iH58T90Z
2 Respostas
+ 1
You don't need to iterate over whole range (from 2 to number).
prime number will never be more than square root of number.
also you algorithm is not correct it gives wrong results.
This should work:
def solve3(number):
compire = 0
for sequence in range(2, int(number**0.5)):
while number % sequence == 0:
compire = sequence
number = number / sequence
return compire
+ 1
Thanks,
andriy kan. Now I get it.