What is the largest prime factor of the number 600851475143 ?

Generating prime factors is another simple algorithm. We divide off all of the 2’s, then we take off the 3’s, but from there we skip two instead of one as we already pulled out all of the possible even factors.

12345678910111213141516171819202122232425

functionGet-PrimeFactors{param([long]$number)while($number%2-eq0){2$number/=2}$bound=[Math]::Sqrt($number)for($i=3;$i-le$bound;$i+=2){while($number%$i-eq0){$number/=$i$i}}$number}functionSolve-Problem3{Get-PrimeFactors600851475143|select-last1}Write-Host"Elapsed Time (s): "(Measure-Command{Solve-Problem3}).TotalSecondsWrite-Host"Solution: "(Solve-Problem3)ElapsedTime(s):0.0477742Solution:6857