Largest Prime Factor
The prime factors of are and .
What is the largest prime factor of the number ?
Solution
Start with the smallest prime factor, , and divide the number by it until it is no longer divisible. Then move on to the next candidate factor, , and repeat. Continue until the number is . Note that if a candidate is a factor, it must be prime, since any composite factor would have smaller prime factors that would have already been found.
Another level of optimization is to only check factors up to the square root of the number, since any factor larger than that would have a corresponding factor smaller than that, and we would have already found it.