Solved Problem 7 using the Sieve of Eratosthenes.