Problem 76: complete solution. (similar to 31).