Let $n \ge 1$ be an integer.
We define a total order on $\mathbb{Z}^n$ as follows.
Let $(r_1,\dots, r_n)$, $(s_1,\dots, s_n) \in \mathbb{Z}^n$.
Let $k = \min \{i; r_i \neq s_i\}$.
Then $(r_1,\dots, r_n) > (s_1,\dots, s_n)$ if and only if $r_k > s_k$.
Lemma 1
Let $r, s, t \in \mathbb{Z}^n$.
Suppose $r > s$.
Then $r + t > s + t$.
Proof:
Clear.
Lemma 2
Let $r, s, r', s' \in \mathbb{Z}^n$.
Suppose $r + s = r' + s'$ and $r > r'$.
Then $s' > s$.
Proof:
$r - r' = s' - s$.
By Lemma 1, $r - r' > 0$.
Hence $s' - s > 0$.
Hence $s' > s$ by Lemma 1.
QED
Let $A$ be a UFD.
Let $p$ be a prime element of $A$.
Let $x \in A$.
If $x$ is divisible by $p^a$ but not by $p^{a+1}$, we denote this fact by $p^a||x$.
Let $f \in A[X_1,\dots, X_n]$.
We denote by $C(f)$ the gcd of all the coefficients of $f$.
If $(C(f)) = (1)$, $f$ is called primitive.
Let $\mathbb{N}$ be the set of integers $\ge 0$.
We denote $(r_1,\dots, r_n) \in \mathbb{N}^n$ by $r$.
We denote a monomial $X_1^{r_1}\cdots X_n^{r_n}$ by $X^r$.
Lemma 3
Let $A$ be a UFD.
Let $f, g \in A[X_1,\dots, X_n]$.
Then $(C(fg)) = (C(f)C(g))$.
Proof:
Let $f = \sum_r \lambda_r X^r$.
Let $g = \sum_s \mu_s X^s$.
Let $fg = \sum_m \gamma_m X^m$. Then $\gamma_m = \sum_{r+s = m} \lambda_r\mu_s$.
Let $p$ be a prime element of $A$.
Suppose $p^a||C(f)$ and $p^b||C(g)$.
It suffices to prove that $p^{a+b}||C(fg)$.
It is clear that $p^{a+b}|C(fg)$.
Let $h = max \{r \in \mathbb{N}^n\colon \lambda_r$ is not divisible by $p^{a+1}\}$.
Let $k = max \{s \in \mathbb{N}^n\colon \mu_s$ is not divisible by $p^{b+1}\}$.
Let $r, s \in \mathbb{N}^n$.
Suppose $r + s = h + k$.
If $r \neq h$, then $\lambda_r\mu_s$ is divisible by $p^{a+b+1}$ by Lemma 2.
Since $\gamma_{h+k} = \sum_{r+s = h+k} \lambda_r\mu_s$, $\gamma_{h+k}$ is not divisible by $p^{a+b+1}$.
QED
Proposition
Let $A$ be a UFD, $K$ its field of fractions.
Let $f \in A[X_1,\dots, X_n]$ be non-constant.
Then $f$ is irreducible if and only if $f$ is primitive and $f$ is irreducible in $K[X_1,\dots, X_n]$.
Proof:
Suppose $f$ is irreducible.
Clearly $f$ is primitive.
Suppose $f = g'h'$, where $g'$ and $h'$ are non-constant polynomial in $K[X_1,\dots, X_n]$.
It is easy to see that there exist primitive polynomials $g, h \in A[X_1,\dots, X_n]$ and $a, b \in A -\{0\}$ such that $af = bgh$.
By Lemma 3, $gh$ is primitive. Hence $b = a\epsilon$, where $\epsilon$ is an invertible element of $A$.
Hence $f = \epsilon gh$.
This is a contradiction.
The converse is clear.
QED