Project Euler problem 14 in C