simple C++ solution for 45