The number of ring homomorphisms from $\mathbb{Z}_m$ to $\mathbb{Z}_n$ I face the problem of finding how many non-trivial ring or group homomorphisms there are from $\mathbb{Z}_m$ to $\mathbb{Z}_n$, where $m<n$. Is there any general formula? 
At the moment, I want to know how many ring homomorphisms there are when $m=12,n=28$.
Please help. 
 A: Hint: regardless of whether you're considering ring or group homomorphisms, where you send $1$ determines where you must send everything else, because for any $n$,
$$f(n)=f(\underbrace{1+\cdots+1}_{n\text{ times}})=\underbrace{f(1)+\cdots+f(1)}_{n\text{ times}}$$
But where can you send $1$? Remember, the resulting function must be a homomorphism:
$$f(a+b)=f(a)+f(b)\qquad f(ab)=f(a)f(b)$$
Try to figure out what conditions this imposes on your choice of $f(1)$. See user26857's answer if you are stuck.
Note that the answer will depend on whether you require that a ring homomorphism $f:R\to S$ must preserve multiplicative identities, i.e. $f(1_R)=1_S$.
A: A ring homomorphism $f:\mathbb Z_m\to \mathbb Z_n$ is uniquely determined by the conditions: $mf(1)=0$ and $f(1)^2=f(1)$.
In order to find out how many ring homomorphisms there are we have to count the number of elements of the set $\{e\in\mathbb Z_n:e^2=e,me=0\}$. It is not hard to see that this equals $2^{\omega(n)-\omega(n/(m,n))}$, where $\omega(a)$ is the number of distinct prime factors of $a$. (See Gallian and Van Buskirk, The Number of Homomorphisms from $\mathbb Z_m$ to $\mathbb Z_n$, AMM, 91(1984), 196-197.)
For particular cases we don't need the above result. For instance, if $m=12$ and $n=28$ we get $0=me=12e$  in $\Bbb Z_{28}$ iff $28\mid 12e$ iff $\,7\mid e,\,$ so $  f(1)\in\{0,7,14,21\}$ and only $0$ and $21$ are idempotent in $\Bbb Z_{28},$ so there are two ring homomorphisms from $\mathbb Z_{12}$ to $\mathbb Z_{28}$.
Edit. If one asks $f(1)=1$ then the problem becomes trivial: there is a unitary ring homomorphism iff $n\mid m$.
