I wrote this code to find prime numbers, but how could I change it to find Mersenne prime numbers?
def prime_test_list(n,known_primes):
k = 1
stop_val = len(known_primes)
if(n>2):
while k<stop_val:
cprime = known_primes[k]
if n%cprime == 0:
return 0
else:
k+=1
return 1
else:
return 1
def prime_print_list(a):
n = 2
known_primes = [1]
while(n<a):
val = prime_test_list(n,known_primes)
if(val==1):
known_primes.append(n)
n+=1
print known_primes
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…