A dynamic solution for Euler problem 18.