This commit is contained in:
2020-07-02 21:28:38 +02:00
parent 09b610492c
commit 50dd110717

View File

@@ -0,0 +1,20 @@
function primeFactorsOf(n) {
let k = 2;
let factors = [];
while (n >= k**2) {
if (n % k === 0) {
factors.push(k)
n = n/k;
} else {
k++;
}
}
factors.push(n);
return factors;
}
const SPECIAL_NUM = 600851475143;
const factorsOfSpecialNum = primeFactorsOf(SPECIAL_NUM);
console.log(Math.max.apply(null, factorsOfSpecialNum));