Preprocess all primes till MAX . Create a boolean array " isPrime [ 0 . . MAX ] " . A value in prime [ i ] will finally be false if i is Not a prime , else true .
isPrime = [ True ] * ( MAX + 1 ) NEW_LINE sieveOfEratosthenes ( isPrime ) NEW_LINE