Workings out from Project Euler.