Solution (source code)

= Solution
{c}

The <identity theorem> states that if two <holomorphic functions> on a <connected> <open set> agree at a <sequence> of distinct points with an <accumulation point> inside that set, then they agree everywhere on it. Equivalently, the zeros of a <holomorphic function> which is not identically zero cannot accumulate inside its <domain>.

Because $f,g$ never vanish, their <logarithmic derivatives> are <holomorphic>. The <holomorphic function>
$$
H=\frac{f'}f-\frac{g'}g
$$
vanishes at every $a_n$. Since the distinct $a_n$ converge to $a\in U$, the <identity theorem> gives $H\equiv0$. Applying the <quotient rule> now gives
$$
\left(\frac fg\right)'=\frac{f'g-fg'}{g^2}=\frac fg\left(\frac{f'}f-\frac{g'}g\right)=0.
$$
A <holomorphic function> with zero <derivative> on a <domain> is constant. One can see this locally from its <Taylor series>, then propagate the constant using <connectedness>. Hence $f/g=c$ on $U$, with $c\ne0$, and
$$
\boxed{f=cg\text{ on }U.}
$$
The conclusion can fail if the accumulation occurs outside $U$. Take the <punctured complex plane> $U=\mathbb C\setminus\{0\}$ and
$$
f(z)=\exp(\cos(1/z)),\qquad g(z)=1,\qquad a_n=\frac1{n\pi}\quad(n\geq1).
$$
Both <functions> are nowhere vanishing and <holomorphic> on $U$, and $a_n\to0\notin U$. The <chain rule> gives
$$
\frac{f'(z)}{f(z)}=\frac{\sin(1/z)}{z^2},\qquad \frac{g'(z)}{g(z)}=0,
$$
so these <logarithmic derivatives> agree at every $a_n$. However, $f$ is not constant: for example $f(1/\pi)=e^{-1}$ and $f(1/(2\pi))=e$. Therefore no constant $c$ gives $f=cg$.