Simple C++ solution for 49