- #1
- 1,120
- 1
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.
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)
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:
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