Problem 58 solution and problem 59 solution