how do I find number of numbers having product of its digits and sum of its digits both equal to given number N

378 Views Asked by At

I want algorithm for a big given $N<10^5$ , say for $4$ ,we have numbers $22$ and $4$ only .I approached it in this way : Say we have $12$ as $N$ , then if it is prime and one digit then return $1$ else $0$ . If not then find all the ways in which $12$ can be written as it's factors' product like $2\times 2\times 3$ so in the number we can have $22311111$ now find it's all permutations then do it for $4\times 3$ so -> $4311111$ find it's permutations then $2\times 6$ we have $261111$ find it's permutations and finally add all the permutations and return it. For a small number I have it's factors $\{2,3,4,6\}$ but how do I get it's factor combinations and there occurrences so that I can add $1$s and find their (factors) permutations with 1s efficiently?