I'm trying to come up with a program that works out Mersenne prime numbers, I've successfully managed to get one to work that brute force attacks the problem and gets me up to 2^2281 - 1 as about the highest prime I can get with the computer still running fine.(adsbygoogle = window.adsbygoogle || []).push({});

I've been reading up and it seems one of the best ways is to use the Lucas-Lehmer Test (http://mathworld.wolfram.com/Lucas-LehmerTest.html) however I am fairly new to matlab and don't quite seem to get it to work. Could anyone give me some points where I am going wrong please.

(Below is code I have used to test if 2^p - 1 is prime or not)

(z records the biggest value of p such that 2^p - 1 is prime)

Code (Text):

p=sym(2)

for p=2:100

if issymprime(p)==sym('true')

s = 4

for s=4:(p-2)

s = mod(s^2 - 2,2^p -1)

end

if s==mod(0,2^p-1)

z=p

end

end

end

**Physics Forums | Science Articles, Homework Help, Discussion**

Join Physics Forums Today!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Lucas-Lehmer Test

**Physics Forums | Science Articles, Homework Help, Discussion**