-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_simple.py
More file actions
50 lines (42 loc) · 1.05 KB
/
Copy pathcheck_simple.py
File metadata and controls
50 lines (42 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
'''Перевірка на просість.Дозволяє з геренерувати список простих чисел до n за допомогою решета Ератосфена'''
from time import time
t = time()
def simple(n):
lst = [2]
for i in range(3, n+1, 2):
if i > 10 and i % 10 == 5:
continue
for j in lst:
if j*j-1 > i:
lst.append(i)
break
if i % j == 0:
break
else:
lst.append(i)
return lst
def simple_a(n):#the best
a = list(range(n+1))
a[1] = 0
lst = []
i = 2
while i <= n:
if a[i] != 0:
lst.append(a[i])
for j in range(i, n+1, i):
a[j] = 0
i += 1
return lst
'''Algoritm Evklida'''
def gcd(a, b):
while True:
if b > a:
a, b = b, a
a = a - b
if b == a:
return b
if b == 0:
return a
if __name__ == '__main__':
print(simple_a(1000))
ti = time() - t