Checking prime through sieve of eratosthenes