Optimising problem 12

Optimising the solution to problem 12 by using prime factors.