problem 38 solution with faster prime detection