Created
September 21, 2017 21:42
-
-
Save matinkaboli/c63cb0e70bbb0d9ad1e7a3cfb1b762f6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let primes = []; | |
let inProgress = 600851475143; | |
let primeFactors = []; | |
function isPrime(n) { | |
for (let i = 2; i < n; i++) { | |
if (n % i === 0) { | |
return false; | |
} | |
} | |
return true; | |
} | |
function divideNumber(n) { | |
for (let i = 0; i < primes.length; i++) { | |
if (n % primes[i] === 0) { | |
inProgress = n / primes[i]; | |
primeFactors.push(primes[i]); | |
break; | |
} | |
} | |
} | |
for (let i = 2; i < 200000; i++) { | |
if (isPrime(i)) { | |
primes.push(i); | |
} | |
} | |
while(true) { | |
if (!isPrime(inProgress)) { | |
divideNumber(inProgress); | |
} else { | |
break; | |
} | |
} | |
console.log(inProgress); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment