<s>[INST] Explain the origin of the number of divisors and sum of divisors formulas. I know the basic formulas which are:
For a number $n = p_1^{a_1} p_2^{a_2} \cdot \ldots \cdot p_k^{a_k}$, we have
$d(n) = ( a_1 + 1 )( a_2 + 1 ) \cdot \ldots \cdot (a_k+1)$ and
$S(n) = \frac{p_1^{a_1+1} - 1}{p_1-1} \cdot \frac{p_2^{a_2+1} - 1}{p_2-1} \cdot \ldots \cdot \frac{p_k^{a_k+1} - 1}{p_k-1}$
I found some demonstrations but none close to my level of maths understanding.I want a simple description of how those formulas were found. Basically, explain everything.
 [/INST] Note that $\frac{x^{n+1}-1}{ x - 1} = x^n + x^{n-1} + \dots + x + 1$. Also note that $(a_1 + \dots + a_n) \cdot (b_1 + \dots + b_m)$ is the sum of all possible combinations of $a_ib_j$. From this you should be able to figure out $S(n)$.
Note that, in the expression of $S(n)$, if instead of the divisors we could have $1$s, that would be $d(n)$. We can make them $1$ if instead of $p_i^{a_i} + \dots + p_i + 1$ you'd have $1^{a_i} + \dots + 1 + 1 = a_i+1$. Thus $d(n)$ can be explained in terms of $S(n)$.
</s>