파이썬 3 124 123 바이트
i=3
q=[2]
while 1:
p=1
for x in range(2,round(i**.5)+1):p=min(p,i%x)
if p:
q+=[i];s=(i-1)/2
if s in q:print(s)
i+=2
어떻게 작동합니까?
i=3 # Start at 3
q=[2] # Create list with first prime (2), to be list of primes.
while 1: # Loop forever
p=1 # Set p to 1 (true)
for x in range(2,round(i**0.5)+1): # Loop from 2 to the number's square root. x is the loop value
p=min(p,i%x) # Set p to the min of itself and the modulo of
# the number being tested and loop value (x).
# If p is 0 at the end, a modulo was 0, so it isn't prime.
if p: # Check if p is 0
q+=[i] # Add the current number (we know is prime) to list of primes (q)
s=(i-1)/2 # Generate s, the number that you would double and add 1 to make a prime.
if s in q:print(s) # If (i-1)/2 is a prime (in the list), then that prime satifies
# the condition 2p+1 is prime because i is 2p+1, and i is prime
i+=2 # Increment by 2 (no even numbers are prime, except 2)
여기에서 온라인으로 사용해보십시오 .
내 컴퓨터에 따르면 2 ^ 32 미만의 모든 Sophie Germain 소수 중 0.023283 %가 생성되었습니다.
완료되면 충분한 줄이 있으면 pastebin에 게시합니다. 당신은 그들 모두를 가지고 있는지 확인하는 데 사용할 수 있습니다.