Why am I getting the wrong result with the Lucas Lehmer Riesel Test?

122 Views Asked by At

The Lucas Lehmer Riesel Test can test if a number of a certain form is prime or composite. Let $N=6143$. I already know this number is prime so the should find $N \vert u_{n-2}$ but the test ends with $u_{n-2}=531$.

$N$ can be written as $k\cdot2^n-1=3 \cdot 2^{11} -1$ so $u_o=5778$ according to the Wikipedia article since $k=3$.

I have written a simple Python program.

p=11
k=3
M=(2**11)-1
u=5778
for i in range(p-2):
  u = ((u*u)-2) % M
  print("u_{} = {}".format(i+1, u))

The output is

u_1 = 759
u_2 = 872
u_3 = 945
u_4 = 531
u_5 = 1520
u_6 = 1382
u_7 = 71
u_8 = 945

What is going wrong?

u_9 = 531

2

There are 2 best solutions below

2
On BEST ANSWER

You’re not actually using $k$ (nor $p$); you wrote M=(2**11)-1instead of M=k*(2**p)-1.

21
On

I have written this simple Magma program:

N := 6143;
u := 5778;
for i in [1..9] do
    u := (u*u - 2) mod N;
end for;
u;

Output:

$0$