Solve problem 47 using C++ and Python.