# Time complexity O(MX * log log MX)MX =1_000_001is_prime = [False] *2+ [True] * (MX -2) # 0 and 1 are not primeprimes = []
for i inrange(2, MX):
if is_prime[i]:
primes.append(i)
for j inrange(i * i, MX, i):
is_prime[j] =False# j is a multiple of prime i
204. Count Primes
p[i] represents the number of primes less than or equal to i. Starting from i=2, p[i]==0 <=> i is prime. Then, starting from ii, mark multiples of i as composite (by setting p[ik]=-1). And, p[i] is assigned p[i-1]+1.