Problem 45: complete solution.