solve problem 31, 32 39