Math Help - Number of Homomorphisms from Zn to Zm

1. Number of Homomorphisms from Zn to Zm

Let $Hom\{\mathbb{Z}_n, \mathbb{Z}_m\}$ denote the group of homomorphisms between $\mathbb{Z}_n$ and $\mathbb{Z}_m$. Show that $|Hom\{\mathbb{Z}_n, \mathbb{Z}_m\}|=gcd(m,n)$.

The only thing I have is that since we're dealing with a homomorphism that $|\phi(a)|$ divides $|a|$, but I don't see how that fact gets used to prove the above statement.

2. Originally Posted by mathematicalbagpiper
Let $Hom\{\mathbb{Z}_n, \mathbb{Z}_m\}$ denote the group of homomorphisms between $\mathbb{Z}_n$ and $\mathbb{Z}_m$. Show that $|Hom\{\mathbb{Z}_n, \mathbb{Z}_m\}|=gcd(m,n)$.

The only thing I have is that since we're dealing with a homomorphism that $|\phi(a)|$ divides $|a|$, but I don't see how that fact gets used to prove the above statement.
for an $f \in Hom\{\mathbb{Z}_n, \mathbb{Z}_m\}$ suppose $f(1+n\mathbb{Z})=k + m \mathbb{Z}.$ then $f(r+n\mathbb{Z})=kr + m\mathbb{Z}.$ for all $r.$ show that $f$ is well-defined if and only if $\frac{m}{d} \mid k,$ where $d=\gcd(m,n).$