TITLE: Number of homomorphisms between two cyclic groups.
QUESTION [17 upvotes]: Is it true that the number of homomorphisms between any two finite cyclic groups of order $m\,\&\,n$ is $\gcd(m,n)$?
I have posted an answer which I believe is true, just wanted to know different approaches to this problem.

REPLY [16 votes]: Let us consider homomorphisms $\mathbb Z_m\to\mathbb Z_n$. Let us denote $d=\gcd(m,n)$.

Since $1$ is generator of $\mathbb Z_m$, the choice of $f(1)=a\in\mathbb Z_n$ uniquely determines all values of $f$. Namely we get
$$f(k) = f(k\times 1)= k\times f(1) = k\times a.$$
(Here $k\times b$ denotes the addition $\underset{\text{$k$-times}}{\underbrace{b\oplus b\oplus \dots\oplus b}}$, where $\oplus$ denotes the addition in the given group, in this case either $\mathbb Z_m$ or $\mathbb Z_n$. I chose this notation to distinguish it from the usual addition of integers.)
But not all choices of $a$ are possible. We definitely need
$$f(0) = f(m\times 1) = m\times a = 0.$$
I.e., $ma \equiv 0 \pmod n$. 
This gives us that $ma=nb$ for some integer $b$. If we divide both sides by $d$, we get
$$\frac md a = \frac nd b.$$
Since $\frac nd$ and $\frac md$ are coprime, this implies that $$\frac nd \mid a.$$
But there are exactly $d$ such numbers in $\mathbb Z_n$, namely the numbers $0,\frac{n}d, \frac{2n}d,\dots, \frac{(d-1)n}d$.
So we see that there are at most $d$ homomorphisms $\mathbb Z_m\to\mathbb Z_n$. 

It remains to check somehow that for any choice of $a$ such that $m\times a=0$ (i.e., one of the $a$'s described above) the function given by
$$f(k) = k\times a$$
is indeed a homomorphism.
If $k,l\in\mathbb Z_m$, then we want to check whether
$$f(k\oplus l) = f(k) \oplus f(l),$$
i.e., whether
$$((k+l)\bmod m)\times a = (k\times a + l\times a)\bmod n.$$
We can write
$$((k+l)\bmod m)\times a \overset{(1)}=
(k+l)\times a \overset{(2)}=
k\times a \oplus l\times a \overset{(3)}=
 (k\times a + l\times a)\bmod n.$$
$(1)$ is true since $m\times a=0$
$(2)$ follows simply from properties of groups. (I will link to a similar proof for rings. But the basic idea is the same and this should be fairly obvious.)
$(3)$ is simply the definition of the operation $\oplus$ on the group $\mathbb Z_n$.