Solution to sieve exercise