TITLE: Find how many positive divisors a number has. What would you do?
QUESTION [12 upvotes]: Recently I learned an amazing thing. Suppose you are given a number and you have to find how many positive divisors it has. What would you do ?
Solution: Suppose you select $12$. It has $1,2,3,4,6,12$ as its divisors; so, total number of divisors of $12$ is $6$.
Now the method I learned:
$x={p_1}^a {p_2}^b$, where $p_1$ and $p_2$ are prime numbers. Now, $x$ has $(a+1)(b+1)$ positive divisors.
Note: Here $x$ can be expressed as a product of many primes with appropriate power.
I want to know the logic behind this.

REPLY [6 votes]: Let's consider an example for 12. We know that
$$
12 = 2^2\cdot 3^1.
$$
Now observe the following expression:
$$
({2}^{0} + {2}^{1} + {2}^{2}) \cdot ({3}^{0} + {3}^{1}).
$$
As you can see, each of the terms achieved after expanding is a divisor of $12$.
And hence the formula for the number of divisors $= (3)(2) = (2 + 1)(1 + 1) = 6$.
You can try this for any number.