Solution to Project Euler, Problem 3 - C++