Test if a Mersenne number is prime using the Lucas-Lehmer test. It can be done by first write a function that generates the sequence used in the test. Given a Mersenne number with exponent , the sequence can be defined as enter image description here
Write a function that accepts the exponent of a Mersenne number and returns the Lucas-Lehmer sequence up to =−2 (inclusive). Remember that the modulo operation is implemented in Python as %.
Use your function to calculate the Lucas-Lehmer series for $p = 17$ , and the result should follow the format below:
ll_result = [4] * 16
My code is as follows:
ll_result = []
def lucas_lehmer(p):
if p == 2:
return 4
for p in range(3,p):
return (lucas_lehmer(p-1)**2-2)%((2**p)-1)
ll_result.append(ll_result())
lucas_lehmer(17)
And the output of my code is: 0
Please help me to identify my mistakes. Thanks