How to get all the factors of a number using its prime factorization?

Expand the following expression: $$(2^0+2^1+2^2)(3^0+3^1)(5^0+5^1)(7^0+7^1)$$ Each combination of four choices (e.g. $2^2, 3^1, 5^0, 7^1$, whose product is $2^23^15^07^1=84$) gives a distinct factor of $420$.


By way of example of a table of factors, just to check we're talking about the same thing:

The factors of $8=2^3$ are of course just $2^0, 2^1, 2^2, 2^3$ or calculated out $1,2,4,8$.

The factors of $9=3^2$ are $3^0, 3^1, 3^2$ aka $1,3,9$.

Now the factors of $72$ can be made up by combining two numbers chosen, one from each of these two sets:

\begin{array}{c|ccc} \times & 1 & 2 & 4 & 8 \\\hline 1 & 1 & 2 & 4 & 8 \\ 3 & 3 & 6 & 12 & 24 \\ 9 & 9 & 18 & 36 & 72 \\ \end{array}

This is no doubt the kind of table you are thinking of.

For $420$ we could apply this process repeatedly, just feeding the contents of each table into one axis of the next table:

\begin{array}{c|ccc} \times & 1 & 2 & 4 \\\hline 1 & 1 & 2 & 4 \\ 3 & 3 & 6 & 12 \\ \end{array}

\begin{array}{c|ccc} \times & 1 & 2 & 4 & 3 & 6 & 12 \\\hline 1 & 1 & 2 & 4 & 3 & 6 & 12 \\ 5 & 5 & 10 & 20 & 15 & 30 & 60 \\ \end{array}

\begin{array}{c|ccc} \times & 1 & 2 & 4 & 3 & 6 & 12 & 5 & 10 & 20 & 15 & 30 & 60 \\\hline 1 & 1 & 2 & 4 & 3 & 6 & 12 & 5 & 10 & 20 & 15 & 30 & 60\\ 7 & 7 & 14 & 28 & 21 & 42 & 84 & 35 & 70 & 140 & 105 & 210 & 420\\ \end{array}

or for a slightly more attractive final table we could split the factors into more equal subsets, here the factors of $2^23^1 =12$ across the top and the factors of $5^17^1=35$ down the side.

\begin{array}{c|ccc} \times & 1 & 2 & 4 & 3 & 6 & 12 \\\hline 1 & 1 & 2 & 4 & 3 & 6 & 12 \\ 5 & 5 & 10 & 20 & 15 & 30 & 60\\ 7 & 7 & 14 & 28 & 21 & 42 & 84 \\ 35 & 35 & 70 & 140 & 105 & 210 & 420\\ \end{array}


Well... yeah. They are all the numbers that are in the form $2^a3^b5^c7^d$ where $0 \le a \le 2; 0 \le b\le 1; 0 \le c\le 1;0 \le d\le 1;$

Just list them all:

$2^03^05^07^0 = 1$

$2^13^05^07^0 = 2$

$2^23^05^07^0 = 4$

$2^03^15^07^0 =3$

$2^13^15^07^0 =6$

....etc...

Less typing: they are $1,2,4,3,6,12,5,10,20,15,30,60,7,14,28,21,42,84,35,70,140,105,210,420$

In general if $N=\prod p_i^{k_i}$ just list every possible $\prod p_i^{m_i}$ where for each $m_i$ $0\le m_i \le k_i$.