From 8a05f86e74a1927298336fea23f9676d97c3b422 Mon Sep 17 00:00:00 2001 From: tejasvicsr1 Date: Mon, 18 Oct 2021 20:24:38 +0530 Subject: [PATCH] Solves issue #1077. Solution to the problem Count Primes(204) in Python. --- Python/204_Count_Primes.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 Python/204_Count_Primes.py diff --git a/Python/204_Count_Primes.py b/Python/204_Count_Primes.py new file mode 100644 index 0000000..d0cf1d1 --- /dev/null +++ b/Python/204_Count_Primes.py @@ -0,0 +1,15 @@ +class Solution: + def countPrimes(self, n: int) -> int: + prime = [True for i in range(n+1)] + p = 2 + while (p * p <= n): + if (prime[p] == True): + for i in range(p * p, n+1, p): + prime[i] = False + p += 1 + sol = 0 + for p in range(2, n): + if prime[p]: + sol += 1 + return sol + \ No newline at end of file