I have some random figure let's say 400, I need equation to find all possible combinations (of integer) whose multiplication will results in 400. Condition is number of factors (multiplicand) will be dynamic.
For example, for 400 with two factors I need output as
1 * 400
2 * 200
4 * 100
5 * 80
etc...
means all a and b where a * b = 400.
Same with 3 factors,
1 * 1 * 400
1 * 2 * 200
2 * 2 * 100
etc...
mean all a, b, and c where a * b * c = 400. We can do this by iterating loop for each possibility, but this approach takes longer time. I need solution that can give answer in minimum possible time. Thanks.
It looks like you're looking only at positive integers, so we'll stick with that. Also, you're looking for an algorithm more than you're looking for an equation.
First, find the prime factorization of the number. Let's say it's composed of the product of $N$ prime factors (which may be repeated, of course).
All of the terms in any of your products will need to be these factors, or products of these factors, or $1$, or the number itself.
To find all of the possible products with $M$ terms, you'll need to find all of the possible products with $1, 2, \dots, min(M,N)$ terms, but for each case, you'll only need to find them once. (The function $min(N,M)$ means the minimum of $M$ and $N$.) Here's why.
You show three cases for three-term solutions for the product of $400$: $$1 \times \ 1 \times 400 = 400, \\ 1 \times \ 2 \times 200 = 400, \\ 2 \times \ 2 \times 100 = 400.$$
The first one is really a trivial extension of a one-term answer: $400.$ It's just padded with $1$'s.
The second one is really a trivial extension of a two-term answer: $2 \times 200.$ It's just padded with a $1$.
The third one is a non-trivial three-term answer.
So the set of all possible products with $M$ terms ($M \leq N$) is the set of non-trivial products with $M$ terms, plus all of the trivial ones created by padding products of $1, 2, \dots, M-1$ terms with the appropriate number of $1$'s.
If $M > N$, then there are no non-trivial products left, so you'll simply pad all of the products (trivial and non-trivial) with $M-N$ $1$'s, and those will be the products in addition to the ones you found for $M \leq N$.