Third problem from ProjectEuler.net