Sieve of Eratosthenes implementation for problem 3