$n$th roots of entire functions I am stuck on this complex analysis problem.

Let $f$ be an entire function and $n$ a positive integer. Show that
  there exists an entire function $g$ such that $f=g^n$ if and only if
  the order of each zero of $f$ is divisible by $n$.

I can see that locally around each $z_0$ we can write $f(z)=(z-z_0)^{nk}s(z)$ where $s(z)$ has no zeroes in a neighborhood of $z_0$ and so there exists a logarithm of $s(z)$, say $l(z)$, which means that $g(z)=(z-z_0)^ke^{l(z)/n}$ works, but I don't understand how to get an entire function from this. I know that it suffices to show that this construction gives functions that agree on the overlap of these neighborhoods, but I don't see why they would have to agree.
 A: In order to prove the result, we will first construct an $n^{th}$ root in any open disc $D(r)$ of radius $r$, $r > 0$ around the origin. Then, by taking a sequence of values of $r$ that go off to infinity, we can patch together the roots to get an entire function.
First, it helps to recall a slightly less local logarithm construction. The proof of the following theorem works in almost the exact same way as the usual proof of the local existence of a logarithm in a simply connected domain (i.e. by constructing a primitive $F$ such that $F'(z) = \frac{f'(z)}{f(z)}$).
Theorem: If $f(z)$ is a holomorphic function defined on some domain $\Omega$ such that $f(z)$ is nonvanishing on this domain, then there is a holomorphic function $g(z)$ defined on $\Omega$ such that $e^{g(z)} = f(z)$ for all $z \in \Omega$.
Now, let $r > 0$ be fixed. Since $\overline{D(r)}$ is compact, we know that $f$ can have finitely many zeroes in $\overline{D(r)}$ and hence finitely many zeroes in $D(r)$.
Now, let $z_1, \ldots, z_N$ be the finitely many zeroes of the given entire function $f$ in $D(r)$. Let the order of $z_i$ be $nk_i$. Now, let $$\tilde{f}(z) = \frac{f(z)}{(z - z_1)^{nk_1} \cdots (z - z_N)^{nk_N}}$$
Then $\tilde{f}$ is non-vanishing on $D(r)$ since it is clearly nonvanishing at the $z_i$, and entire since it is a quotient of meromorphic functions with the same order at each $z_i$. 
Thus, there is a logarithm $\ell$ of $\tilde{f}$ defined on the simply connected domain $D(r)$. We have that $e^{\ell(z)} = \tilde{f}(z)$, so $\tilde{g}(z) = e^{\frac{\ell(z)}{n}}$ satisfies $\tilde{g}(z)^n = \tilde{f}(z)$. Now, since $f(z) = \tilde{f}(z) (P(z))^n$, where $P(z)$ is the polynomial $\prod_i (z-z_i)^{k_i}$. Thus, letting $g(z) = \tilde{g}(z)P(z)$, we have our desired $n^{th}$ root. 
Now, we can "patch together" our $n^{th}$ roots on each $D(N)$, $N \in \mathbb{N}^{+}$. Define $g_1$ to be the $n^{th}$ root constructed above on $D(1)$.
Assume that we've successfully defined $g_k$ such that for all $\ell < k$, $g_k|_{D(\ell)} = g_{\ell}$. Now, let $g'_{k+1}$ be an $n^{th}$ root for $f$ on $D(k+1)$. It may not be the case that $g'_{k+1}|_{D(k)} = g_k$. However, we have that on $D(k)$:
$$
\left(\frac{g'_{k+1}(z)}{g_k(z)}\right)^n = \frac{g'_{k+1}(z)^n}{g_k(z)^n} = \frac{f(z)}{f(z)} = 1
$$
Thus, for all $z \in D(k)$, we have that $h(z) = \frac{g'_{k+1}(z)}{g_k(z)}$ satisfies $h(z)^n = 1$, and thus $h(z) \in \{e^{2\pi i \frac{m}{n}}\}_{m = 1, \ldots, n}$. Since $h(z)$ is holomorphic and thus in particular continuous on $D(k)$, we have that $h(z)$ is constant of value $\zeta \in \{e^{2\pi i \frac{k}{n}}\}_{k = 1, \ldots, n}$ for all $z \in D(k)$. Thus, let $g_{k+1} = \zeta^{-1}g'_{k+1}$. Then, for $z \in D(k)$, we have $g_{k+1}(z) = \zeta^{-1} h(z) g_k(z) = g_k(z)$. 
Now for any $\ell \leq k$, we have that $g_{k+1}|_{D(\ell)} = (g_{k+1}|_{D(k)})|_{D(\ell)} = g_k|_{D(\ell)} = g_\ell$ by the induction hypothesis. Thus, we construct by induction $g_N$ for all $N \in \mathbb{N}^+$. Finally, we may define $g(z)$ by: $g(z) = g_N(z)$ for any $N$ such that $z \in D(N)$. By the above proof, we know that these are all equal, so this is well-defined. In addition, if $z \in D(N)$, then some small neighborhood $U$ of $z$ is in $D(N)$ as well. Thus, $g(z)|_U = g_N(z)|_U$, and this is holomorphic on $U$. Thus, $g(z)$ is entire. Since $g_N(z)^n = f(z)$ for $z \in D(N)$, we have that $g$ satisfies $g(z)^n = f(z)$ for all $z \in \mathbb{C}$. 
The converse is easy to see by a local argument. Let $f  = g^n$ where $f, g$ are entire. If $z_0$ is a zero of $f$, then in some neighborhood $U$ of $z_0$, $f(z) = (z-z_0)^m s(z)$ where $s(z)$ is nonvanishing in $U$. Since $g$ must vanish at $z_0$ but not anywhere else on $U$, we must have $g(z) = (z-z_0)^k t(z)$ for some $k \geq 1$ and $t(z)$ nonvanishing on $U$. Thus, $f(z) = (z-z_0)^{nk} t(z)^n$. Since $t(z)^n$ is nonvanishing on $U$, we must have that $t(z)^n = s(z)$ and thus $nk = m$, so the order $m$ of the zero $z_0$ is divisible by $n$.
A: The one direction is clear, if $f = g^n$, and $z_0$ is a zero of $f$, then $z_0$ is a zero of $g$, say of order $k$, so in a neighbourhood of $z_0$ we have $g(z) = (z-z_0)^k\cdot h(z)$ with a holomorphic nonzero $h$. Then in that neighbourhood $f(z) = (z-z_0)^{nk}\cdot h(z)^n$, and of course $h(z)^n$ is nonzero there. So indeed $n$ divides the order of the zero of $f$ at $z_0$.
Conversely, let all zeros of $f$ have orders divisible by $n$. The case $f \equiv 0$ is trivial, so in the following we assume $f\not\equiv 0$. Consider the entire meromorphic function
$$h_0(z) = \frac{f'(z)}{f(z)}.$$
Since $f$ is entire, the poles of $g$ are exactly the zeros of $f$. Let $P$ be the pole set of $g$ and $U = \mathbb{C}\setminus P$.
All poles of $h_0$ are simple, with the residue of $h_0$ in $z_0$ being the order of the zero of $f$ at $z_0$: If $f(z) = (z-z_0)^m\cdot k(z)$ with a holomorphic nonzero $k$ in a neighbourhood of $z_0$, then
$$\frac{f'(z)}{f(z)} = \frac{m(z-z_0)^{m-1}\cdot k(z) + (z-z_0)^m\cdot k'(z)}{(z-z_0)^m\cdot k(z)} = \frac{m}{z-z_0} + \frac{k'(z)}{k(z)}$$
in that neighbourhood, and $\frac{k'}{k}$ is holomorphic there since $k$ is nonzero.
All residues of $h_0$ are multiples of $n$, hence the entire meromorphic function $h = \frac{1}{n}\cdot h_0$ has integer residues.
Now choose an $a \in U$, and for every $z\in U$ choose a - piecewise continuously differentiable - path $\gamma_z \colon [0,1] \to U$ with $\gamma_z(0) = a$ and $\gamma_z(1) = z$. Then define $\lambda \colon U \to \mathbb{C}$ by
$$\lambda(z) := \int_{\gamma_z} h(\zeta)\,d\zeta.$$
The function $\lambda$ depends on the choice of the path $\gamma_z$, but if we choose a different path $\delta_z$ from $a$ to $z$, then the composition $\gamma_z\delta_z^{-1}$ is a closed path in $U$, and $n(\gamma_z\delta_z^{-1},\omega) \neq 0$ for only finitely many $\omega\in P$. Hence
\begin{align}
\int_{\gamma_z} h(\zeta)\,d\zeta - \int_{\delta_z} h(\zeta)\,d\zeta
&= \int_{\gamma_z\delta_z^{-1}} h(\zeta)\,d\zeta\\
&= 2\pi i \sum_{\omega\in P} n(\gamma_z\delta_z^{-1},\omega)\operatorname{Res}(h;\omega)\\
&\in 2\pi i\cdot \mathbb{Z},
\end{align}
so a different choice of paths alters $\lambda(z)$ by an integer multiple of $2\pi i$, whence $g_0 \colon U\to \mathbb{C}$ given by
$$g_0(z) = \exp(\lambda(z))$$
is independent of the choice of paths. The independence of the choice of paths shows that $g_0$ is holomorphic: For $w\in U$ and $r > 0$ such that $D_r(w) \subset U$, we can define
$$\tilde{\lambda}(z) = \lambda(w) + \int_w^z h(\zeta)\,d\zeta$$
on $D_r(w)$, which is holomorphic, and we have
$$\exp(\tilde{\lambda}(z)) \equiv \exp(\lambda(z))$$
on $D_r(w)$ by the independence of $g_0$ from the choice of paths. Also, this shows that $g_0'(z) = \frac{f'(z)}{nf(z)}\cdot g_0(z)$.
Now we see that $f\cdot g_0^{-n}$ is constant on $U$ by differentiation:
$$(f\cdot g_0^{-n})'(z) = f'(z)\cdot g_0^n(z) - nf(z)\cdot g_0^{n-1}(z)\cdot g_0'(z) = f(z)g_0^n(z)\biggl( \frac{f'(z)}{f(z)} - n\frac{g_0'(z)}{g_0(z)}\biggr) = 0.$$
Hence, for a suitable $c\in \mathbb{C}\setminus \{0\}$, $g(z) := c\cdot g_0(z)$ is a holomorphic $n$-th root of $f$ on $U$.
But for $\omega\in P$ we have
$$\lim_{z\to \omega} g(z) = 0,$$
hence these are all removable singularities and $g$ extends to an entire function.
