Skip to content

Instantly share code, notes, and snippets.

@adilek
Last active November 3, 2018 16:06
Show Gist options
  • Save adilek/02f53ebd3b23b21c40eebc70b077290e to your computer and use it in GitHub Desktop.
Save adilek/02f53ebd3b23b21c40eebc70b077290e to your computer and use it in GitHub Desktop.
Sophie_2.py
import time
import math
def is_prime(a):
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
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