PUZZLE PE-003
Largest Prime Factor
Project Euler · Problem 3
Original problem
The prime factors of
What is the largest prime factor of the number
Formal statement
For
find
where
Hints
Open one at a timeRemove each small factor completely before continuing.
When the loop ends, the remaining number may itself be prime.
Solution
Best opened after a real attemptApproach
Start with the smallest possible divisor. Whenever the current divisor divides the remaining value, divide it out completely before moving on. Each successful division shrinks the unresolved part of the factorization.
It is enough to test divisors while
Code & final result
The original problem is reproduced from Project Euler Problem 3 under CC BY-NC-SA 4.0.