solved problem 27 with the help of quinny's PrimeSieve class