Number of Homomorphisms from $\Bbb{Z}_m$ to $\Bbb{Z}_n$
In general, if $G$ is any group, then you can show that the number of homomorphisms $\mathbb{Z}_m \rightarrow G$ is the number of solutions to $x^m = 1$ in $G$. How many solutions are there to $x^m = 1$ in $\mathbb{Z}_n$?
HINT: If $h:\Bbb Z_m\to\Bbb Z_n$ is a homomorphism, $\big|h[\Bbb Z_m]\big|\cdot|\ker h|=m$, and $\big|h[\Bbb Z_m]\big|$ divides $n$.
I am not sure if this is the correct way to go but look good to me hence, I am sharing.
Let $f$ be the homomorphism from $\Bbb Z_{m} \to \Bbb Z_{n}$
Since $O(f([1]_{n})) \space | \space O(\Bbb Z_{n}) \implies O(f([1]_{n})) \space | \space n$
Also $O(f([1]_{n})) \space | \space m $
Hence number of homomorphism = $\gcd(n, m)$