Where does this function come from in this proof? This is an excerpt taken from a proof:
Let each $M_n(n\in\mathbb{N})$ be countable,
Then there exists an injective function $f_n:M_n\rightarrow\mathbb{N}$.
Now, set a function $k:\bigcup_nM_n\rightarrow\mathbb{N}$ to be such that for each $a\in\bigcup_nM_n$,
$k(a)=\min\{j\mid a\in M_j\}$
Then the injection $f:\bigcup_nM_n\rightarrow\mathbb{N}$ is given by the following $f(a):=p_{k(a)}^{f_{k(a)}+1}$
where $p_{k(a)}$ is the $k(a)$-th prime number.
Question: I don't understand where this last identity for $f(a)$ comes from.
My understanding (or lack there of):
I feel comfortable understanding the domain $M_n$ and that each element is injectively mapped to an element in $\mathbb{N}$
I'm thinking of the function $k$ as a function that selects the first $M_j$ with $a$ in the domain.
So for $f(a)$ we map every $M_j$ up to $n$, but only from the function $f$ up to the first $M_j$ containing $a$
Becoming more confused the more I think about this...
 A: Here's an illustration. Suppose
$$M_1=\{1\} \quad M_2=\{2,3\} \quad M_3=\{4,5,6\} \quad M_4=\{7,8,9,10\} \quad \cdots $$
and
$$\begin{array}{llll} M_1\to\Bbb N: & \color{Red}{f_1(1)=0} \\ M_2\to\Bbb N: & \color{Purple}{f_2(2)=0} & \color{Purple}{f_2(3)=1} \\ M_3\to\Bbb N: & \color{Blue}{f_3(4)=0} & \color{Blue}{f_3(5)=1} & \color{Blue}{f_3(6)=2} \\ M_4\to\Bbb N: & \color{Green}{f_4(7)=0} & \color{Green}{f_4(8)=1} & \color{Green}{f_4(9)=2} & \color{Green}{f_4(10)=3} \\ \cdots \end{array} $$
Then
$$\begin{array}{r} \color{Red}{f(1)=2^1} \\ \color{Purple}{f(2)=3^1} \\ \color{Purple}{f(3)=3^2} \\ \color{Blue}{f(4)=5^1} \\ \color{Blue}{f(5)=5^2} \\ \color{Blue}{f(6)=5^3} \\ \color{Green}{f(7)=7^1} \\ \color{Green}{f(8)=7^2} \\ \color{Green}{f(9)=7^3} \\ \color{Green}{f(10)=7^4} \end{array} $$
Thus, the prime number base of $f(a)$ tracks which $M_j$ an $a$ is in, and the exponent indicates which element of $M_j$ it is. This fact about how $f$ works is true no matter what the individual sets $M_1,M_2,M_3,\cdots$s are (they could even be infinite) or what the $f_1,f_2,f_3,\cdots$s are, although clearly by changing those sets and functions you do change the function $f$.
Inspiration. Prime factorization is essentially a map from $\Bbb N^{\oplus\Bbb N}$ (natural number-indexed sequences of natural numbers with all but finitely many coordinates zero) to $\Bbb N$ given by
$$(e_0,e_1,e_2,\cdots)\mapsto 2^{e_0}3^{e_1}5^{e_2}\cdots $$
In order to construct the map $\bigcup M_j\to\Bbb N$ from the $f_j$, we just need to use $f_j$ to embed $M_j$ into the $j$th coordinate of $\Bbb N^{\oplus\Bbb N}$ and then use the above map.
