I want the fastest way in Mathematica 7 to generate a list of the factors (not prime factors) of an integer into a specified number of terms, with each factor greater than one.For example, 240 into three terms:{{2,2,60}, {2,3,40}, {2,4,30}, {2,5,24}, {2,6,20}, {2,8,15}, {2,10,12}, {3,4,20}, {3,5,16}, {3,8,10}, {4,4,15}, {4,5,12}, {4,6,10}, {5,6,8}}My starting code is based on a recursive method the source of which I have forgotten, but probably someone on projecteuler.net:f[n_, 1, ___] := {{n}}f[n_, k_, x_: 2] := Join @@ Table[   If[q < x, {}, {q, ##} & @@@ f[n/q, k - 1, q]],   {q, # ~Take~ Length@#/k & @ Divisors @ n} ]f[240, 3]Memoization can be applied in several places.  In the case of large integers this is much faster, at the expense of memory usage of course.  Here, with memoization at three points:Clear[f, div]div@n_ := div@n = Divisors@ndiv[n_, k_] := div[n, k] = # ~Take~ Length@#/k & @ div @ nf[n_, 1, ___] := {{n}}f[n_, k_, x_: 2] := f[n, k, x] = Join @@ Table[   If[q < x, {}, {q, ##} & @@@ f[n/q, k - 1, q]],   {q, n~div~k}  ]Compared to Sasha's code on a large composite integer:f[10080^2, 5] // Length // Timing   {0.891, 103245}FactorIntoFixedTerms[10080^2, 5] // Length // Timing   {25.594, 103245}Can this be further improved?
List of integer factorization into n terms
algorithm;wolfram mathematica