Solved prob 10 using the Sieve of Eratosthenes