Last active
November 3, 2018 16:06
-
-
Save adilek/e97690d1510136db4cc27a3e2d0a7c38 to your computer and use it in GitHub Desktop.
Sophie Germain
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
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, 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