Problem 46 solution