Problem 3 "Maximum prime factor"
The prime factors of 13195 are 5, 7, 13, 29. Find the largest of the prime factors of 600851475143.
Python
target = 600851475143
x = target
i = 2
prime_factors = []
while x > 1:
if x % i == 0:
prime_factors.append(i)
x = x / i
else:
i += 1
result = max(prime_factors)
print result
print result == 6857
print prime_factors
result
6857
True
[71, 839, 1471, 6857]
Recommended Posts