Topic Content: Find the nth number of Moenissen. P is prime and M is prime, and satisfies the equation m=2**p-1, then the M is called Moenissen number. For example, p=5,m=2**p-1=31,5 and 31 are primes, so 31 is a Moenissen number.
input Format: Enter with the input () function, noting the return type of this function in Python 3.
output format: int type
Input Sample: 4
Output Sample: 127
Time limit: 500ms memory limit: 32000kb
train of thought: Prime number dozen + enumeration
AC Code:
#-*-Coding:utf-8-*-
import Math
def prime (n): # To determine whether the prime number
if n < 2: return
False to I in
rang E (2, int (MATH.SQRT (n)) + 1):
if n% i = = 0: Return
False return
True
def monisen (MAXN):
" " # prime number dozen
Prime_dic = {}
prime_list = []
n = 10000
for I in range (2, n + 1):
prime_dic[i] = 1
F or I in range (2, int (n * *. 5) + 1):
for J in range (I * I, n + 1, i):
if prime_dic[i] = = 1:
prime_dic[j] = 0
for K, v. in Prime_dic.items ():
If v = 1:
prime_list.append (k)
' ' for
i in prime_list:
# enumeration 2**prime-1 to MAXN
Mon = 2 * * I-1
if Prime (Mon):
maxn = maxn-1
if MAXN <= 0: Return
m On
print Monisen (input ())