+ 2

I am new to python and dont know the advanced features or stuff. Please explain the following code step by step. how it works.

Its a code to get the greatest mersenne prime within an upper limit of value. Describe the sieve of eratosthenes also. #largestmersenneprime 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 list=[] def mersennePrimes(n) : prime = [0] * (n + 1) SieveOfEratosthenes(n, prime) k = 2 while(((1 << k) - 1) <= n ): num = (1 << k) - 1 if (prime[num]) : list.append(num) k += 1 n = int(input("enter upper limit (893452 suggested) : ")) mersennePrimes(n) print("largest Mersenne prime numbers smaller than or equal to " , n ,"is : ",list[-1])

22nd Jan 2021, 3:31 AM
Akash Adhikary
Akash Adhikary - avatar
3 ответов
22nd Jan 2021, 4:16 AM
Vrajesh Sulakhe
Vrajesh Sulakhe - avatar
22nd Jan 2021, 4:18 AM
Vrajesh Sulakhe
Vrajesh Sulakhe - avatar
0
Akash Adhikary Where is ur code
22nd Jan 2021, 3:35 AM
Abhay
Abhay - avatar