0

Task : describe a predicate (on Prolog) that count all possible variants of representation of natural number N as product of natural numbers. For example, 6 = 6*1 = 2*3, so answer is 2. The program itself isn't a problem, but main algorithm is hard for me. I get stuck

Simankov
  • 131

1 Answers1

2

For a given number $N$ with prime factorization $p_1^{a_1}p_2^{a_2}\cdots p_k^{a_k}$, the total number of positive integer factors is given by the well-known formula, $d(N)=(a_1+1)(a_2+1)\cdots(a_k+1)$.

The factors generally pair up to give $N$ as a product of two factors. For instance, $24=2^3\cdot 3$ has $(3+1)(1+1)=8$ factors, which pair up to give $24=1\cdot 24=2\cdot 12=3\cdot8=4\cdot 6$

However in the case that $N$ is a perfect square, there is one factor (namely $\sqrt{N}$ that pairs with itself.

Thus the number of ways of writing $N$ as a product of two factors is $\left\lceil\frac{d(N)}{2}\right\rceil$, where $\lceil x\rceil$ is the ceiling function of $x$.

paw88789
  • 41,907
  • thank you! No doubt, brilliant answer. Unfortunately i mistaken in explanation, so variants like 24 = 432 is possible. Can i use first formula from you answer? – Simankov May 29 '15 at 20:52