Last active
November 3, 2018 16:06
-
-
Save adilek/4c868f044547182847d6190d83b02423 to your computer and use it in GitHub Desktop.
Sofiya_2.py
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 | |
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