human
Mersenne Prime | Generate all prime numbers less than n ..
Initialize all entries of boolean array as true . A value in prime [ i ] will finally be false if i is Not a prime , else true bool prime [ n + 1 ].
If prime [ p ] is not changed , then it is a prime.
Update all multiples of p.
Function to generate mersenne primes less than or equal to n.
Create a boolean array " prime [ 0 . . n ] ".
Generating primes using Sieve.
Generate all numbers of the form 2 ^ k - 1 and smaller than or equal to n ..
Checking whether number is prime and is one less then the power of 2.
Driver Code"
Solution in Python:
assistant
#Here is code to mersenne Prime and the other steps required.
 def SieveOfEratosthenes ( n , prime ) :
	for i in range ( 0 , n + 1 ) :
		prime [ i ] = True
	p = 2
	while ( p * p <= n ) :
		if ( prime [ p ] == True ) :
			for i in range ( p * 2 , n + 1 , p ) :
				prime [ i ] = False
		p += 1
def mersennePrimes ( n ) :
	prime = [ 0 ] * ( n + 1 )
	SieveOfEratosthenes ( n , prime )
	k = 2
	while ( ( ( 1 << k ) - 1 ) <= n ) :
		num = ( 1 << k ) - 1
		if ( prime [ num ] ) :
			print ( num , end = " ▁ " )
		k += 1
n = 31
print ( " Mersenne ▁ prime ▁ numbers ▁ smaller " , " than ▁ or ▁ equal ▁ to ▁ " , n )
mersennePrimes ( n )