If $a$ is irreducible and $a\nmid fg$, then $a\mid f$ or $a\mid g$? I'm trying to understand the proof of the following:
Theorem. Let $D$ be a unique factorization domain and let $a\in D$ be an irreducible element. If $f, g\in D[x]$ are such that $a\mid fg$, then $a\mid f$ or $a\mid g$.
The idea is to show that
$$a\nmid f\quad \textrm{and}\quad a\nmid g\implies a\nmid fg.$$
Let us write
\begin{align*} 
f(x)=f_0+f_1 x+\ldots+f_n x^n\quad \textrm{and}\quad g(x)=g_0+g_1 x+\ldots+g_m x^m.
\end{align*}
If $a\nmid f$ and $a\nmid g$ then we can find $i\in \{1, \ldots, n\}$ and $j\in \{1, \ldots, m\}$ such that $$a\nmid f_i\quad \textrm{and}\quad b\nmid g_j.$$
We can then define
$$p:=\min\{i\in \{1, \ldots, n\}: a\nmid f_i\ \textrm{and}\ a\mid f_j\ \forall j<i\}$$
and
$$q:=\min\{i\in \{1, \ldots, m\}: a\nmid g_i\ \textrm{e}\ a\mid g_j\ \forall j<i\}.$$
By definition
$$a\nmid f_p\quad \textrm{and}\quad a\nmid g_q.$$
Consequently, since $a$ is irreducible,
$$a\nmid f_p g_q.$$
I have already shown that if $a$ is irreducible and $a|bc$, then $a|b$ or $a|c$.
Now, define
$$h_{p+q}=f_0 g_{p+1}+\ldots+f_p g_q+\ldots+f_{p+q} g_0$$
where $f_i=g_j=0$ if $i>n$ and $j>m$.
I'd like to conclude that $$a\nmid h_{p+q}$$ using the fact that $a\nmid f_p g_q$, for this will imply $a$ does not divide the coefficient of $x^{p+q}$ of the product $fg$, and hence does not divide $fg$ (for I have already show that if $a\mid f$ for some $f\in D[x]$, then $a$ divides every coefficient of $f$).
So, my question is, why
$$a\nmid f_p g_q\implies a\nmid h_{p+q}?$$
It does not seem straightforward because there could be a term in the sum which defines $h_{p+q}$ that could cancel $f_p g_q$. Why can't this happen?
Thanks.

Your expression for $h_{p+q}$ seems off to me.
Writing the coefficient of $x^{p+q}$ in $fg$, $$h_{p+q}=f_0g_{p+q}+f_1g_{p+q-1}+\cdots+ f_{p-1}g_{q+1}+f_pg_q+f_{p+1}g_{q-1}+\cdots+f_{p+q}g_0.$$
Now by the assumption on divisibility of $a$ and $p, q$, we have that $a$ divides all the terms in RHS except $f_pg_q$.
Thus, $a|h_{p+q}$ iff $a| f_pg_q$.
