Count Primes



Problem to find the number of prime number until the given number.



Example-1:


Input    : n = 10
Output   : 4
Explain  : There are 4 Prime numbers are 2,3,5,7 until the given number.  


Example-2:


Input    : n = 20
Output   : 8
Explain  : There are 8 Prime numbers are 2,3,5,7,11,13,17,19 until the given number.   







Solution




n = 10

if(n <= 2):

    print(0)

l = set()

l.add(2)

for i in range(3,n,2):

    for j in l:

        if(i % j == 0):

            break
    else:

        l.add(i)
        
print(len(l))



Output



4