Solve problem 142 using C++.