your task is to write a program that uses the Lucas-Lehmer primality test to check whether an input number is prime or not. This prime number candidate has the form 2p-1
with p being prime. (Mersenne prime number)
The Lucas-Lehmer-test
The n-th Mersenne number is prime if it is a divisor of the (n-1)-th Lucas-Lehmer number (LLN). You can calculate the LLN, similiar to the Fibonacci numbers, based on a recursive algorithm:
L<n> = (L<n-1>)^2 - 2
The LLN for 2 is 14. So, for p=3, LLN<3-1>=14
Evaluation
- You have to submit a function that takes p as input (Remember:
2^p-1
) - The shortest solution will win.
- Your solution has to use the Lucas-Lehmer test
- The code must be executable.
- Output: boolean value or 1=prime/0=not prime
Tests:
p --> 2^p-1 --> LLN<n-1> --> ?
3 --> 7 --> 14 --> prime
5 --> 31 --> 37634 > prime (1214*31)
Good Luck
unobservable criteria
\$\endgroup\$