We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 50545d1 commit 8b8fba3Copy full SHA for 8b8fba3
maths/segmented_sieve.py
@@ -15,15 +15,12 @@ def sieve(n):
15
if temp[start] is True:
16
in_prime.append(start)
17
for i in range(start * start, end + 1, start):
18
- if temp[i] is True:
19
- temp[i] = False
+ temp[i] = False
20
start += 1
21
prime += in_prime
22
23
low = end + 1
24
- high = low + end - 1
25
- if high > n:
26
- high = n
+ high = min(2 * end, n)
27
28
while low <= n:
29
temp = [True] * (high - low + 1)
@@ -41,9 +38,7 @@ def sieve(n):
41
38
prime.append(j + low)
42
39
43
40
low = high + 1
44
45
46
+ high = min(high + end, n)
47
48
return prime
49
0 commit comments