Solve problem 3

Key insight: stop at sqrt(x)