Gauss lemma
Let $R$ be a UFD and $F$ its field of quotients.
Let $f=\sum_{i=0}^n a_ix^i \in R[X]$ with $a_0 \neq 0$. If $p$ and $q$ are non zero, coprime elements in $R$, such that $\dfrac{p}{q} \in K$ is root of $f$, show that $\dfrac{a_0}{p},\dfrac{a_n}{q} \in R$.
I am trying to prove this lemma though I couldn't do much, using the hypothesis we get $$(1) \space 0=a_0+a_1\dfrac{p}{q}+...+a_n(\dfrac{p}{q})^n,$$
from (1) we get the two following equations $$(2) \space a_0=p(-\sum_{i=1}^n a_i \dfrac{p^{i-1}}{q^i})$$ $$(3) \space a_n=q(-\sum_{i=1}^n a_{n-i}\dfrac{q^{i-1}}{p^i})$$
I have to arrive to the conclusion that $r=(-\sum_{i=1}^n a_i \dfrac{p^{i-1}}{q^i})$ and $s=(-\sum_{i=1}^n a_{n-i}\dfrac{q^{i-1}}{p^i})$ are in $R$, I don't know how to deduce this so any suggestions would be appreciated.