Problem 23, full solution