The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number 600851475143 ?
function largestPrimeFactor(num: number): number {
let largestPrime: number = 0;
let i: number = 2;
while (i <= num) {
if (num % i === 0) {
largestPrime = i;
num = num / i;
} else {
i++;
}
}
return largestPrime;
}
Thoughts:
This is the last one I had solved myself before copilot was a thing, another while loop from copilot, but it does the job.