How to get all the factors of a number using its prime factorization? For example, I have the number $420$. This can be broken down into its prime factorization of $$2^2 \times3^1\times5^1\times7^1 = 420 $$
Using $$\prod_{i=1}^r (a_r + 1)$$ where $a$ is the magnitude of the power a prime factor is raised by and $r$ is the number of prime factors. I get $24$ possible factors.
Is there an easy way to iterate through all those $4$ factors to obtain all $24$? I know this can be easily done using a table with numbers with only $2$ factors. But, as this one has $4$ I obviously can't implement the table method. So any general solution to do this? Thanks!

If
$n = \prod_{i=1}^r p_i^{a_i}
$
is the prime factorization on $n$,
there are
$\prod_{i=1}^r (a_i + 1)
$
prime factors.
Look at this
as counting a
$r$-digit number in a variable base,
with the base of the
$i$-th digit being
$a_i+1$,
so that digit goes from
$0$ to $a_i$.
If
$b_i$ is the $i$-th digit,
then the value corresponding
to that digit is
$p_i^{b_i}$.
Here is my take
on a moderately efficient algorithm
to compute all the 
possible factors.
The divisor starts at $1$.
When a digit is incremented,
the value of the divisor
is multiplied by $p_i$.
If the $i$-th digit
exceeds $a_i$,
it is set to zero,
the divisor divided by
$p_i^{a_i}$,
and the next digit is examined.
Initialize
$d = 1$
(the divisor)
and
$b_i = 0$
and
$c_i = p_i^{a_i}$
for $i=1$ to $r$
(the exponents and max powers of $p_i$).
$\text{do forever}\\
\quad\text{output } d\\
\quad\text{for }i=1\text{ to }r\\
\qquad \text{if } b_i<a_i\text{ then } b_i=b_i+1; d=d\cdot p_i; \text{ exit for loop}
\quad\text{(digit did not overflow)}\\
\qquad\text{else } b_i=0; d=d/c_i
\quad\text{(digit overflowed - reset and look at next digit)}\\
\quad\text{end for}\\
\quad\text{if }d=1\text{ then exit do loop}
\quad\text{(all digits overflowed - done)}\\
\text{end do}\\
$
