From 831cc19eaea2190997e677c76dc7996c70c674f2 Mon Sep 17 00:00:00 2001 From: KillMonger1 <35474707+KillMonger1@users.noreply.github.com> Date: Fri, 2 Oct 2020 18:47:34 +0530 Subject: [PATCH] Create sieveOfEratosthenes.py --- .../algorithms/other/sieveOfEratosthenes.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 src/main/python/algorithms/other/sieveOfEratosthenes.py diff --git a/src/main/python/algorithms/other/sieveOfEratosthenes.py b/src/main/python/algorithms/other/sieveOfEratosthenes.py new file mode 100644 index 0000000..046e6ee --- /dev/null +++ b/src/main/python/algorithms/other/sieveOfEratosthenes.py @@ -0,0 +1,16 @@ +def SieveOfEratosthenes(n): + pr=[True for i in range(n + 1)] + primes=2 + while (primes*primes<=n): + if (pr[primes]==True): + for i in range(primes*2,n+1,primes): + pr[i] = False + primes+=1 + pr[0]= False + pr[1]= False + for p in range(n + 1): + if pr[p]: + print(p) + +n = int(input()) +SieveOfEratosthenes(n)