My solution to this problem, although it can be generalized to any finite abelian group $\displaystyle G$, is not straightforward. See if you can find a simple solution:

Let $\displaystyle p$ be a prime number. Let $\displaystyle G_1$ and $\displaystyle G_2$ be cyclic groups of orders $\displaystyle p$ and $\displaystyle p^2$ respectively. Let $\displaystyle G=G_1 \times G_2.$ Findthe numberof group homomorphisms $\displaystyle f: G \longrightarrow G.$