Skip to content

Instantly share code, notes, and snippets.

@adilek
Last active November 3, 2018 16:05
Show Gist options
  • Save adilek/c60b3d73a484e0f15af0e0bee23a61bb to your computer and use it in GitHub Desktop.
Save adilek/c60b3d73a484e0f15af0e0bee23a61bb to your computer and use it in GitHub Desktop.
Sofiya_3.py
import time
import math
SIZE = 100000 * 2 + 1
primes = [False] * SIZE
primes[2] = True
def is_prime(a):
if (primes[a]):
return True
if a == 1:
return False
if a == 2:
return True
if a % 2 == 0:
return False
for i in range(3, int(math.sqrt(a)) + 1):
if a % i == 0:
return False
primes[a] = True
return True
def is_sophie_germain(a):
return is_prime(a) and is_prime(2 * a + 1)
start_time = time.time()
num = 0
for i in range(100000):
if (is_sophie_germain(i)):
num += 1
# print(i)
print("---------------------")
print("Sofi nənə ədədlərinin sayı: %s" % (num))
print("%s saniyə" % (time.time() - start_time))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment