Given a number N, find the number of combinations of its factors (excluding 1 and N), which on multiplication yield N. Eg:
N = 12
answer = 3
relevant factors : 2,3,4,6
combinations : {2,6},{3,4},{2,2,3}.
To solve this, I came up with the following logic, which is adequate for nearly all cases, but undercounts in a few cases. Please help me in understanding what I am missing. My Logic:
I divide the set of combinations into "primary" and "secondary". The ones which occur as a direct combination of the factors are primary. In the above example, {2,6} and {3,4} are primary. Those which come up as a result of further breaking one of the original factors is secondary. Eg: {2,2,3} can be called a combination of 2 with breakdown of 6 into {2,3} or of 3 with breakdown of 4 into {2,2}.
For every number, I first find the number of primary factors, then the number of secondary factors by recursively repeating the process for the largest relevant factor. Eg:
f(32) = 2 + f(16);
f(16) = 2 + f(8);
f(8) = 1 + f(4);
f(4) = 1;
Thus, f(32) = 6.
In the above, the primary combinations of 32 are {2,16} and {4,8}. Hence the 2 in the first step. This explains rest of the steps too.
The problem is, this solution fails for a few values of N. Eg: It returns 8 for 90, but the correct answer is 10. It returns 16 for 180, but the correct answer is 25. For 60, correct is 10, but mine is 9.
Please help me.