From 40c55a91730af2002e13b436514c7c1563675c21 Mon Sep 17 00:00:00 2001 From: harshlohia11 Date: Sun, 13 Sep 2020 17:57:14 +0530 Subject: [PATCH 1/2] Counting number of primes sieve of eralothenes --- algorithms/miscellaneous/sieveoferalothenes.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 algorithms/miscellaneous/sieveoferalothenes.py diff --git a/algorithms/miscellaneous/sieveoferalothenes.py b/algorithms/miscellaneous/sieveoferalothenes.py new file mode 100644 index 00000000..0952e281 --- /dev/null +++ b/algorithms/miscellaneous/sieveoferalothenes.py @@ -0,0 +1,12 @@ +import math +n=int(input("Enter the number")) +isPrime=[] +for i in range(n): + isPrime.append(True) +isPrime[0]=False +isPrime[1]=False +for i in range(2,int(math.sqrt(n)),1): + for j in range(2*i,n,i): + isPrime[j]=False +for i in range(0,n,1): + print(i,":",isPrime[i]) \ No newline at end of file From ae97c2e4ec6692a92adf6a9aab6a36801bd343ff Mon Sep 17 00:00:00 2001 From: harshlohia11 Date: Sun, 13 Sep 2020 18:05:04 +0530 Subject: [PATCH 2/2] Counting number of primes sieve of eralothenes --- algorithms/miscellaneous/sieveoferalothenes.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/algorithms/miscellaneous/sieveoferalothenes.py b/algorithms/miscellaneous/sieveoferalothenes.py index 0952e281..19802cda 100644 --- a/algorithms/miscellaneous/sieveoferalothenes.py +++ b/algorithms/miscellaneous/sieveoferalothenes.py @@ -1,12 +1,13 @@ +#this progran will check for prime numbers to a certain range and if the prime is prime it will display True else False import math n=int(input("Enter the number")) isPrime=[] for i in range(n): - isPrime.append(True) + isPrime.append(True) #assigning the array to False uptil n isPrime[0]=False isPrime[1]=False for i in range(2,int(math.sqrt(n)),1): - for j in range(2*i,n,i): + for j in range(2*i,n,i): #checking for prime numbers isPrime[j]=False for i in range(0,n,1): print(i,":",isPrime[i]) \ No newline at end of file