ٍProblem description:
The prime factors of 13195 are 5, 7, 13 and 29. Largest prime factor 13195 is 29.
What is the largest prime factor of the number 600851475143 ?
Prime Factor:
any of the prime numbers that can be multiplied to give the original number.
Example:
Find the prime factors of 100:
100 ÷ 2 = 50; save 2
50 ÷ 2 = 25; save 2
25 ÷ 2 = 12.5, not evenly so divide by next highest number, 3
25 ÷ 3 = 8.333, not evenly so divide by next highest number, 4
But, 4 is a multiple of 2 so it has already been checked, so divide by next highest number, 5
25 ÷ 5 = 5; save 5
5 ÷ 5 = 1; save 5
List the resulting prime factors as a sequence of multiples, 2 x 2 x 5 x 5 or as factors with exponents, 2^2 x 5^2.
My Solution
This is my solution for problem 3 of Project Euler using Python:
def FLPF(n):
'''Find Largest Prime Factor
'''
PrimeFactor = 1
i = 2
while i <= n / i:
if n % i == 0:
PrimeFactor = i
n /= i
else:
i += 1
if PrimeFactor < n: PrimeFactor = int(n)
return PrimeFactor
50 ÷ 2 = 25; save 2
2 was already saved, does it make sense to save it again? \$\endgroup\$