TITLE: Number of automorphisms of a direct product of two cyclic $p$-groups
QUESTION [16 upvotes]: Suppose I have $G = Z_{p^m} \times Z_{p^n}$ for $m, n$ distinct natural numbers and $p$ a prime. Is there a combinatorial way to determine the number of automorphisms of $G$?

REPLY [8 votes]: $\def\ZZ{\mathbb{Z}}$
It's worth pointing out that Arturo's answer 2 generalizes very nicely to all abelian $p$-groups: Consider $G = \bigoplus \ZZ/p^{\lambda_i}$; let $\mu_{\ell}$ be the number of $\lambda$'s which are equal to $\ell$; let $r$ be the number of summands of $G$ (so $r = \sum \mu_i$).
Then $\mathrm{End}(G) \cong \bigoplus \mathrm{Hom}(\ZZ/p^{\lambda_i}, \ZZ/p^{\lambda_j}) \cong \bigoplus \ZZ/p^{\min(\lambda_i, \lambda_j)}$ as abelian groups.
An element of $\mathrm{End}(G)$ is invertible if and only if its image in $\mathrm{End}(G/pG)$ is invertible. (Nakayama's lemma.) Now, $G/pG \cong (\ZZ/p)^r$, so its endomorphism ring is $\mathrm{Mat}_{r \times r}(\ZZ/p)$. The map $\mathrm{End}(G) \to \mathrm{End}(G/pG)$ is NOT surjective. Rather, the image is the block-upper-triangular matrices, where the sizes of the blocks are the $\mu_i$. Such a matrix is invertible iff and only if the diagonal blocks are invertible. So the fraction of $\mathrm{End}(G)$ which is made up of invertible elements is 
$$\prod_{\ell} \frac{|\mathrm{GL}_{\mu_{\ell}}(\ZZ/p)|}{|\mathrm{Mat}_{\mu_{\ell} \times \mu_{\ell}}(\ZZ/p)|} = \prod_{\ell} \frac{(p^{\mu_\ell}-1)(p^{\mu_\ell}-p) \cdots (p^{\mu_\ell} - p^{\mu_\ell -1})}{p^{\mu_{\ell}^2}}$$
$$=\prod_{\ell} \left( 1- p^{-1} \right) \left( 1-p^{-2} \right) \cdots \left( 1-p^{-\mu_{\ell} +1} \right).$$
Putting it all together, $|\mathrm{Aut}(G)|$ is found by multiplying the above formula by $|\mathrm{End}(G)|$ (computed in the second paragraph), and we get
$$|\mathrm{Aut}(G)| = p^{\sum_{i,j} \min(\lambda_i, \lambda_j)} \prod_{\ell} \left( 1- p^{-1} \right) \left( 1-p^{-2} \right) \cdots \left( 1-p^{-\mu_{\ell} +1} \right).$$