*Much* faster algorithm using prime factors rather than evaluating all possible products.
The math is sound, but the Scala implementation feels... inelegant.