Is there an abelian and a nonabelian group with same numbers of elements of each order. Are there finite groups $G$ and $H$ such that:


*

*$n:=|G|=|H|$.

*$G$ is abelian.

*$H$ is nonabelian.

*for every $d\mid n$, $G$ and $H$ have the same number of elements of order $d$.
?


I know two finite abelian groups with the same numbers of elements of each order; are isomorphic. And there are nonabelian groups with the same property which are not isomorphic.
 A: Yes, for any odd prime $p$ there is 


*

*one (isomorphism type of) abelian group $G$ of order $p^3$ and exponent $p^2$, and

*one nonabelian group $H$ of order $p^3$ and exponent $p^2$,


and they have the same number of elements of each possible order, that is, 


*

*1 element of order 1,

*$p^2 - 1$ elements of order $p$, and 

*$p^3 - p^2$ elements of order    $p^2$.


$G$ is the product of a cyclic group of order $p^2$ with a (cyclic) group of order $p$. As to $H$, it has a presentation $\langle a, b : a^{p^2} = b^{p} = 1, [a, b] = a^p \rangle$.
A: The extraspecial $p$-group ($p$ an odd prime) 
$$E_n = \langle x_1,y_1,\ldots,x_n,y_n,z \mid x_i^p=y_i^p=1, z=[x_i,y_i] \textrm{ central }, [x_i,x_j]=[x_i,y_j]=1\rangle$$ 
($i,j=1,\ldots,n,\;i\neq j$) has order $p^{2n+1}$ and exponent $p$ (and is non-abelian). Hence it has the same number of elements in each order as $C_p^{2n+1}=C_p \times \cdots \times C_p$.  
A: This is similar to the answer by Andreas. 
Let $p > 2$ be prime, $G$ be elementary abelian of order $p^3$, $H$ nonabelian of order $p^3$ such that $x^p = 1$ for each $x \in H$. That is, $G \cong \mathbb{Z}_p \times \mathbb{Z}_p \times\mathbb{Z}_p$ and $H$ will be the Heisenberg group
$$H \cong \left\{ \begin{pmatrix} 1 & a & b \\ 0 & 1 & c \\ 0 & 0 & 1 \end{pmatrix} : a, b, c \in \mathbb{Z}_p \right\}$$
In both groups there are $p^3 - 1$ elements of order $p$.
A: Generalising a bit the example of m.k. Let $p$ be an odd prime and $F$ any field of characteristic $p$. Then $GL(n,F)$ does not have any elements of order $p^2$ as long as $n\leq p$: the minimal polynomial of such an element must be a power of $X-1$, but $X^p-1=(X-1)^p$ is divisible by $(X-1)^i$ for all $i\leq n$ in this case, so that elements with minimal polynomial $(X-1)^i$ still have order $p$.
Therefore the group $U$ of upper unitriangular matrices in such $GL(n,F)$, as well as any subgroup of $U$, have the property that all its non-identity elements have order $p$, a property they share with the elementary Abelian $p$-group of the same order, while the group $U$ in not Abelian when $n\geq3$ (this is in fact the only reason $p\neq2$ is relevant).
