The prime factors of 13195 are 5, 7, 13 and 29.
What is the largest prime factor of the number 600851475143 ?
A problem of 'prime factor decomposition'.
Iterate from smallest prime number 2, repeatedly devided by current largest prime factor.
def solve(number):
largest_prime_factor = 1
d = 2
while d ** 2 <= number:
while number % d == 0:
number //= d
largest_prime_factor = d
d += 1
return max(largest_prime_factor, number)
solve(13195)
solve(600851475143)