Power of a function is analytic Question is :

Show that if $f(z)$ is continuous function on a domain $D$ such that $f(z)^N$ is analytic on $D$ for some integer $N$ then $f(z)$ is analytic on $D$..

For some time i was wondering $f(z)=\left|z\right|$ is not analytic... $f^2(z)=z^2$  is analytic so $f(z)=|z|$ has to be analytic but it is not... Then i realized, $f^2(z)\neq |z|^2$ but $f(z)=x^2+y^2$ so what i was thinking was non sense.
Now coming to the point... Supposing $f^2(z)$ is analytic i have to prove that $f(z)$ is analytic.
As of now, i have not came across any theorem that says something is analytic.
I know that for an analytic function zeros are isolated... Zeros of $f^2(z)$ are same as zeros of $f(z)$ so, being isolated is not an issue and does not even help..
Give some hints to solve this. 
 A: Let $g(z)=f(z)^N$. We compute $g'(z)=\displaystyle \lim_{h\to 0}\frac{g(z+h)-g(z)}{h}=Nf(z)^{N-1}\lim_{h\to 0}\frac{f(z+h)-f(z)}{h}$ by basic factorization technique. By this identity we know $f'(z)$ exists at all points $f(z)\neq 0$.
Zeros of $g$ and $f$ are the same and we know $Z(g)=Z(f)$ is either the whole complex plane(in that case $f$ is identically $0$, therefore analytic) or a discrete set.
Suppose $Z(f)$ is discrete from the argument above we know $f$ is analytic at all but possibly a discrete set, and is continuous everywhere. You can use Morera's Theorem (Combine with Cauchy's Theorem) to argue that this condition is sufficient for $f$ to be analytic everywhere.
For any point $z_0\in Z(f)$, let $D=D(z_0,r)$ be the disc that contains no other zeros. We try to prove integrate $f$ along any closed piecewise $C^1$ curve $\gamma$ inside $D$ gives us $0$. If $z_0$ is not enclosed by $\gamma$ then by Cauchy's theorem the integral is clearly zero. If $z_0$ is enclosed by $\gamma$, split $\gamma=\gamma_1+\gamma_2$ such that $z_0\in \gamma_1\cap\gamma_2$, then again by Cauchy's theorem the integral is $0$(function continuous on $\gamma_1\cup\gamma_2$ and analytic in the region enclosed).
