#13 Solver for problem 31