Rosetta Code: Lucas-Lehmer test

Tell us what’s happening:
11 is a prime number so the code should return true. However; it’s failing with: “lucasLehmer(11) should return false”. Everything else works just fine.

Your code so far

function lucasLehmer§ {
if (p < 2) {
return false
let root = Math.ceil(Math.sqrt§);

for(let i = 2; i<=root; i++) {
if(p % i === 0) {
return false;

return true;
console.log(lucasLehmer(11)); true
console.log(lucasLehmer(15)); false
console.log(lucasLehmer(13)); true
console.log(lucasLehmer(17)); true
console.log(lucasLehmer(19)); true
console.log(lucasLehmer(21)); false

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Firefox/78.0.

Challenge: Lucas-Lehmer test

Link to the challenge:

but you are not testing if 11 is prive, you are testing if 211-1 is prime, as that is the Mersenne number

you already know that the input is an odd prine, you need to check if the Mersenne number obtained by that number is prime or not

1 Like

Oh… Ok. That makes sense. Thanks for your help.