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
14 changes: 14 additions & 0 deletions Math/sieve_of_eratosthenes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
def sieve_of_eratosthenes(n):
prime = [True for _ in range(n + 1)]
p = 2
while p * p <= n:
if prime[p]:
for i in range(p * p, n + 1, p):
prime[i] = False
p += 1
primes = [p for p in range(2, n + 1) if prime[p]]
return primes


n = int(input("Enter the number up to which you want to find primes: "))
print("Prime numbers up to", n, "are:", *sieve_of_eratosthenes(n))
Loading