-
Notifications
You must be signed in to change notification settings - Fork 0
/
v10.py
55 lines (40 loc) · 944 Bytes
/
v10.py
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
49
50
51
52
53
54
55
# added break
# filter out even
# filter out even in for loop directly
# limit search to half of i
# limit search to square root of i
# limit search to only previous prime numbers
# limit search to only previous prime numbers but checking for less than directly at list addition rather than during modulus
# check
# taking finding of sqrt of final number as constant outside
import time
start = time.time()
n=100000
p = int(n**0.5)
c = 0
k = 1
l = []
for i in range(3, n, 2):
for j in l:
if i % j == 0:
c += 1
break
if c == 0:
k += 1
if i < p:
l.append(i)
c = 0
print(k)
end = time.time()
print(end - start)
# time took
# 258.44545817375183
# 24.8780837059021
# 23.12345814704895
# 22.465441465377808
# 11.63539743423462
# 0.11180853843688965
# 0.09911322593688965
# 0.03931570053100586
# 0.03710675239562988
#16.366311073303223 for 10000000 values