Solution for euler project problem #8