Skip to content

Instantly share code, notes, and snippets.

@moshiurse
Created May 3, 2021 19:47
Show Gist options
  • Save moshiurse/c3d21d05d6afd23a1f8ae9a87022449e to your computer and use it in GitHub Desktop.
Save moshiurse/c3d21d05d6afd23a1f8ae9a87022449e to your computer and use it in GitHub Desktop.
let numbers = [];
const total = 999999;
function createPrime() {
numbers[0] = 0;
numbers[1] = 0;
numbers[2] = 1;
const sqRt = parseInt(Math.sqrt(total));
for(let i = 3; i < total; i += 2) {
numbers[i] = 1;
}
for(let i = 4; i < total; i += 2) {
numbers[i] = 0;
}
for(let i = 3; i < sqRt; i +=2 ){
for(let j = i * i; j < total; j += i){
numbers[j] = 0;
}
}
}
createPrime();
function isPrime(number) {
if(numbers[number] == 1){
console.log("Yes Its Prime");
}else{
console.log("Nope Its Not a Prime");
}
}
isPrime(111114)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment