Time(true);



LucasLehmer := function(n)
local MP, s, i;

  Print("\nLucas-Lehmer Test fuer 2^",n," - 1\n");

  if n=2 then 
    Print("2^2 - 1 = 3 ist eine Primzahl.\n");
    return true;
  fi;

  MP:=2^n-1;
  s:=4;

  Print("------------------------------------------------------\n");

  for i in [1..(n-2)] do
    s:=(s^2-2) mod MP;
    Print("s_",i," = ",s," mod 2^",n," - 1 \n");
  od;
  
  Print("------------------------------------------------------\n");
  
  if s=0 then
    Print("2^",n," - 1 = ",MP," ist eine Primzahl.\n\n");
    return true;
  else
    Print("2^",n," - 1 = ",MP," ist KEINE Primzahl.\n\n");
    return false;
  fi;
  
  return;
end;