Finding Mersenne primes An attempt to find Mersenne primes using the Lucas-Lehmer primality test:
n=int(input(&quot;Enter n to check if 2^n-1 is a prime:&quot;))
a=4
for i in range(0,n-2):
    b=a**2
    a=b-2
    if i==n-3:
        c=(a)%((2**n) - 1)
        if c==0:
            print((2**n) - 1 ,&quot;is a prime number&quot;)
            break
if c!=0:
    print((2**n) - 1 ,&quot;is not a prime number&quot;)

Can you critique this code? It is apparent that it needs improvement as it doesnt work for n&lt;=2 and computing power increases exponentially for increasing n.
I have been learning python for less than a year, I am only 15 and would love any feedback on this program.
Edit: The confusion with n-2 and n-3 is because we have to check if the (n-1)th term in the series is divisible by l = 2^n - 1 to establish that l is a Mersenne prime. But as you would have noticed the above written code considers the 0th term as 14 which is the 3rd term in the actual series. This means there is a gap of two terms between the actual series and the series procured by the program, therefore to actually study the (n-1)th term in the series , we have to consider the (n-3)th term here. Hence the mess that doesn't allow n to be &lt;=2.
Please provide your opinion on this
The page you linked to has pseudocode, and it does s = ((s × s) − 2) mod M. And right below the pseudocode it says:

Performing the mod M at each iteration ensures that all intermediate results are at most p bits (otherwise the number of bits would double each iteration).

Do that and it'll be much faster.
And better use the same variable names as in the page you referenced, don't make up new ones, that just obfuscates the connection.