TITLE: How many Homomorphisms can be between $Z_6$ to $Z_{18}$?
QUESTION [7 upvotes]: How many Homomorphisms can be between $Z_6$ to $Z_{18}$?
and the most important: What is the algorithm for calculating, step by step?

REPLY [4 votes]: Say we have a homomorphism, $\varphi:Z_n \rightarrow Z_m$. Given that $x \in Z_n$ is determined by $1_{Z_n}$, in the sense
$$
x=\underbrace{1_{Z_m}+1_{Z_m}+\cdots+1_{Z_m}}_{x \text{ times}}
$$
the properties of the homomorphism force the image to be entirely determined by the image of $1_{Z_n}$ under $\varphi$. Why? Observe, let $x \in Z_{n}$
$$
\varphi(x)=\varphi(\underbrace{1_{Z_m}+1_{Z_m}+\cdots+1_{Z_m}}_{x \text{ times}})=\underbrace{\varphi(1_{Z_n})+\varphi(1_{Z_n})+\cdots+\varphi(1_{Z_n})}_{x \text{ times}}
$$ 
All that matters is $\varphi(1_{Z_n})$, so if $1_{Z_n}$ maps to $a \in Z_{m}$ then $x\in Z_n$ must map to $xa$. Now two facts determine all the rest:
$1$. If $|x|=n$, then $|\varphi(x)|$ must divide $n$. 
$2$. Lagrange's Theorem: In any finite group, the order of a subgroup must divide the order of the group. (The converse is not true!)
The two together imply that $|a|$, the image of $\varphi(1_{Z_n})$, must divide not only $n$ (by Lagrange's Theorem) but also $m$ (by Property $1$). 
Now given we want a homomorphism $\varphi:Z_n\rightarrow Z_m$, which numbers $a$ are these? Then how many homomorphisms are there total? Finally, to see the bigger picture, what is $\text{gcd}(6,18)$? Is this a coincidence? What does this mean?