Last active
November 3, 2018 16:05
-
-
Save adilek/fdf42a2757648dd63c654e45106e28ba to your computer and use it in GitHub Desktop.
Sofiya_4.py
This file contains hidden or 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 | |
SIZE = 100000 * 2 + 1 | |
primes = [True] * SIZE | |
primes[0] = False | |
primes[1] = False | |
def generate_primes(): | |
N = int(math.sqrt(SIZE)) | |
for i in range(2, N): | |
if (not primes[i]): | |
continue | |
for j in range(i * 2, SIZE, i): | |
primes[j] = False | |
def is_sophie_germain(a): | |
return primes[a] and primes[2*a+1]; | |
start_time = time.time() | |
generate_primes() | |
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