Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions maths/segmented_sieve.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,12 @@ def sieve(n):
if temp[start] is True:
in_prime.append(start)
for i in range(start * start, end + 1, start):
if temp[i] is True:
temp[i] = False
temp[i] = False
start += 1
prime += in_prime

low = end + 1
high = low + end - 1
if high > n:
high = n
high = min(2 * end, n)

while low <= n:
temp = [True] * (high - low + 1)
Expand All @@ -41,9 +38,7 @@ def sieve(n):
prime.append(j + low)

low = high + 1
high = low + end - 1
if high > n:
high = n
high = min(high + end, n)

return prime

Expand Down