Constructing non-isomorphic groups such that the counts of elements of given order match In one of the simplest ways of proving that two groups aren't isomorphic, we can compare the orders of each element of both groups. If we find an order $\ell$ such that one of the groups has more elements of this order than the other group, we're done.
I am interested in finite groups where this fails --- ones that aren't isomorphic, but the counts for each order are the same:
$$\DeclareMathOperator\ord{ord} G \not\cong H \quad \land \quad \forall\ell.\ |\{g \in G \mid \ord g = \ell\}| = |\{h \in H \mid \ord h = \ell\}|$$
With some SageMath code, I have computed that the smallest groups where this happens are of order 16. However, I am more interested in how one could methodically find such a counterexample, apart from just trying out groups you can think of until something sticks. How would you find such a pair of groups without a computer?
 A: Here is one family of such groups.
The nonabelian group of order $p^3$ and exponent $p$ can be realized as the multiplicative group of $3\times 3$ unipotent matrices with coefficients in $\mathbb{Z}/p\mathbb{Z}$, i.e., matrices of the form
$$\left(\begin{array}{ccc}
1 & a & c\\
0 &1 & b\\
0 & 0 & 1
\end{array}\right),\qquad a,b,c\in \mathbb{Z}/p\mathbb{Z}.$$
In this group, every nontrivial element has order $p$, and so you get the same count as you do for the abelian (an dhence non-isomorphic) group $(\mathbb{Z}/p\mathbb{Z})^3$.
You can also construct further examples, known as extra-special $p$-groups (of exponent $p$), by taking central products of copies of the group above. Let us denote the group above by $\mathbf{E}_3$ ($E$ for "extra-special"; it's a technical term). Note that the center is cyclic of order $3$, given by the matrices with $a=b=0$. Now, we construct $\mathbf{E}_5$ by taking $\mathbf{E}_3\times\mathbf{E}_3/N$, where $N$ is group of elements of the form $(z,z^{-1})$ with $z\in Z(\mathbf{E}_3)$ (this "identifies" the centers of each copy of $\mathbf{E}_3$). This is again a nonabelian group of exponent $p$, with center of order $p$, of order $p^5$.
Assuming we have defined $\mathbf{E}_{2n+1}$, nonabelian group of order $p^{2n+1}$, exponent $p$, and center of order $p$, we construct $\mathbf{E}_{2n+3}$ by identifying generators $w$ and $z$ of $Z(\mathbf{E}_{2n+1})$ and $Z(\mathbb{E}_3)$, and constructing $\mathbf{E}_{2n+1}\times\mathbf{E}_3/N$, where $N$ consists of the elements of the form $(w^k,z^{-k})$. This will be a nonabelian group of order $p^{2n+3}$, exponent $p$, with center of order $p$.
Then $\mathbf{E}_{2k+1}$ and $(\mathbb{Z}/p\mathbb{Z})^{2k+1}$ will have the desired property, for all $k\geq 1$.

Now, say you have (finite) groups $G$ and $H$ as desired (nonisomorphic, but for each $k$ the number of elements of order $k$ in $G$ and $H$ are the same). Let $K$ be any finite group. I claim that $G\times K$ and $H\times K$ also satisfy the desired properties. That they are not isomorphic is not trivial, but nonetheless it is true (e.g., it follows from the Remak-Krull-Schmidt Theorem). Now I claim that for every $r$, the number of elements of order $r$ in $G\times K$ and in $H\times K$ is the same.
An element $(g,k)\in G\times K$ has order $r$ if and only if (i) the order of $g$ divides $r$; (ii) the order of $k$ divides $r$; and (iii) at least one of the orders of $g$ and $k$ is exactly equal to $r$. Thus, letting $G(d)$ be the set of elements of $G$ of order exactly $d$, and similarly for $H(d)$ and $K(d)$, we have that
$$(G\times K)(r) = \left(\sum_{d|r}|G(d)||K(r)|\right) + \left(\sum_{d|r}|G(r)||K(d)|\right) - |G(d)||K(d)|.$$
Similarly,
$$(H\times K)(r) = \left(\sum_{d|r}|H(d)||K(r)|\right) + \left(\sum_{d|r}|H(r)||K(d)|\right) - |H(d)||K(d)|.$$
Since $|G(m)|=|H(m)|$ for all $m$ by assumption, it follows that $|(G\times K)(r)|=|(H\times K)(r)|$.

An interesting question might be to determine all $n$ for which there exist two non-isomorphic groups $G$ and $H$ of order $n$ for which the count of elements of order $k$ is equal for all $k$. From the above, we see that if $n$ divisible by the cube of an odd prime, or by $16$, then such groups exist. We also know that if $n$ is cubefree and a nilpotent number, then every group of order $n$ is abelian, so no such examples exist. This reduces the problem to $n$ that is cubefree but not a nilpotent number, and to numbers of the form $2^km$ where $m$ is odd and cubefree, $k=3$. I expect counterexamples exist in that case as well.
