For which numbers $n$ is every group of order $n$ nilpotent? I would like to have a simple criterion for the numbers $n$ with the property that every group of order $n$ is nilpotent.
If $n$ is a prime power, it is clear that $n$ has this property.
If $n$ is an abelian number (every group of order $n$ is abelian) , then the property is satisfied as well.
So, let's omit those cases.

Which numbers $n$ satisfy the following conditions ?
  
  
*
  
*$n$ is not a prime power.
  
*There is at least one non-abelian group of order $n$.
  
*Every group of order $n$ is nilpotent.
  

The smallest such numbers are $135$, $297$ and $459$, all having the form $3^3p$ , $p$ prime , $p>3$.
The desired sequence does not contain even numbers because the dihedral group $D_{2n}$ is not nilpotent for $n\ge 3$ , unless $2$ is a power of $2$. (Is there an easy proof for that ?)
 A: The characterization of such numbers has been known for a while, see for example "Nilpotent numbers" by Pakianathan and Shankar.
Here is the characterization. Write the prime factorization of $n$ as $n = p_1^{k_1} \cdots p_t^{k_t}$.
Then every group of order $n$ is nilpotent if and only if $p_i^s \not\equiv 1 \mod{p_j}$ for all $i \neq j$ and $1 \leq s \leq k_i$. 
Here is an explanation why the condition is necessary:
If $p_i^s \equiv 1 \mod{p_j}$ for $1 \leq s \leq k_i$, then $p_j$ divides the order of $\operatorname{Aut}((\mathbb{Z}/p_i\mathbb{Z})^s) \cong \operatorname{GL}_s(\mathbb{Z}/p_i\mathbb{Z})$. Thus we can form a nontrivial semidirect product $H = (\mathbb{Z}/p_i\mathbb{Z})^s \rtimes \mathbb{Z}/p_j\mathbb{Z}$. Because $H$ is non-abelian and its Sylow subgroups are abelian, it follows that $H$ is not nilpotent. Then $$H \times (\mathbb{Z}/p_i\mathbb{Z})^{k_i - s} \times (\mathbb{Z}/p_j\mathbb{Z})^{k_j - 1} \times \mathbb{Z} / m \mathbb{Z}$$ for $m = n/{p_i^{k_i} p_j^{k_j}}$ is a non-nilpotent group of order $n$.
Related questions have been asked many times, see here, here, here and here..
