Solution of project Euler #22