forked from DeepNinja07x/Python_Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsieve_of_eratosthenes.py
More file actions
23 lines (17 loc) · 817 Bytes
/
Copy pathsieve_of_eratosthenes.py
File metadata and controls
23 lines (17 loc) · 817 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
n = int(input())
sieve = [True] * n
# inspect until i is equal to sqrt(n) because the greatest divider of n is less than or equal to sqrt(n)
m = int(n ** 0.5)
for i in range(2, m + 1):
if sieve[i] == True: # if i is a prime number,
for j in range(i+i, n, i): # let all multiples of i to false
sieve[j] = False
prime_number_list = [i for i in range(2, n) if sieve[i] == True]n = int(input())
sieve = [True] * n
# inspect until i is equal to sqrt(n) because the greatest divider of n is less than or equal to sqrt(n)
m = int(n ** 0.5)
for i in range(2, m + 1):
if sieve[i] == True: # if i is a prime number,
for j in range(i+i, n, i): # let all multiples of i to false
sieve[j] = False
prime_number_list = [i for i in range(2, n) if sieve[i] == True]