Improve performance of Go's problem 50.
Solve problem 50 using C++.