Writing number as a product

Hello everybody,

I have this problem. I want to write any number P = q1*q2*...*qn+r so that q1+q2+...+qn+|r|+7*n is the least (how do you write a subscript here?). P and each q are natural numbers, n is a natural number or 0, r is an integer.
Do I make sense?

I have no idea how to go about this problem without trying every possible combination.. I'd appreciate any thoughts.