Euler project fast solution for problem 12