all! recently i've been trying to build a mercende prime number producer/generator, using the lucas lehmer method of testing. the code works for the first 4 numbers, and then fails for the rest. any suggestions? thanks!
var totalPrimes = Math.floor(prompt("What would you like the upper limit of
our search for primes to be?"));
for (var i = 2; i < totalPrimes; i++) {
var lucasNum = 4;
var curNumber = (Math.pow(2, (i+1))-1);
for (var x = 0; i-1 > x; x++) {
if (lucasNum / curNumber > 1) {
lucasNum = (Math.pow(lucasNum, 2)-2);
} else {
lucasNum = (Math.pow(lucasNum, 2)-2);
}
}
if (lucasNum % curNumber === 0) {
console.log("The number " + curNumber + " is prime");
} else {
console.log("The number " + curNumber + " is not prime");
}
}