I am looking for an algorithm which presents a given polynomial in many variables (given as a sum of monomials) in a form with the smallest number of multiplications of variables. For example $x_1^2x_3+x_1x_2+x_1x_3x_4 \to x_1(x_2+x_3(x_1+x_4)).$
Of course, one could consider some "dumb" approach testing all possibilities, but I am curious if there is a faster one. I need to do it for over 100,000 of polynomials in over 40 variables each.