Jun-05-2019, 09:57 AM
(This post was last modified: Jun-05-2019, 09:57 AM by Richard_SS.)
The prime factors of 13195 are 5, 7, 13 and 29.
What is the largest prime factor of the number 600851475143 ?
-
I have written a programm for solving this problem, it easily displays prime factors of 13195, but once I insert a bigger number (like 600851475143), a programm goes into an infinite loop, it returns neither error, nor answer. Please help, where is the problem in code?
My code:
What is the largest prime factor of the number 600851475143 ?
-
I have written a programm for solving this problem, it easily displays prime factors of 13195, but once I insert a bigger number (like 600851475143), a programm goes into an infinite loop, it returns neither error, nor answer. Please help, where is the problem in code?
My code:
import math a = [] b = range(1,600851475143) def is_prime(n): if n == 2: return True if n % 2 == 0 or n <= 1: return False sqr = int(math.sqrt(n)) + 1 for divisor in range(3, sqr, 2): if n % divisor == 0: return False return True b = (filter(is_prime,b)) for i in b: if 600851475143 % i == 0: a.append(i) else: pass print (a) print("The largest prime factory is",a[-1::])