Solve problem 38 in C++
Solve problem 41