TITLE: When is $p^n(p^n-1)$ divisible by $2n$
QUESTION [7 upvotes]: Let $n\in\mathbb{N}$.  Then, when is $p^n(p^n-1)$ divisible by $2n$ for all $p$ prime?  I know the following:

$n$ must be $1$ or even. (in the odd case, $p=2$ gives a counterexample).
If $n=2^k$ for $k\geq 0$, then $p^n(p^n-1)$ divisible by $2n$ for all $p$ prime.

There are more values for $n$ that work as well for $p$ prime ($e.g.$ $n=6$). However, for example, $n=10$ does not work ($i.e.$ $2^{10}(2^{10}-1)=1047552$ which is not divisible by $20$). 
Is there something more general to be said?  I'm hoping for a statement along the lines of:

"$p^n(p^n-1)$ divisible by $2n$ for all $p$ prime if and only if $\ldots$"

REPLY [4 votes]: This is a tricky thing to actually compute, in general, but there is an abstract characterization for somewhat simple reasons.
Write
$$n=2^k\cdot p_1^{e_1}p_2^{e_2}\ldots p_r^{e_r}\text{ with }e_i,k>0$$
Let's note that for any $p$ we have $p^{n}$ has greater $p$ divisibility than $2n$, so it remains to show that $p^n-1$ is divisible by a number we will denote as $2\hat{n}$ with

$$\hat{n}=2^kp_1^{e_1}\ldots p_{i-1}^{e_{i-1}}p_{i+1}^{e_{i+1}}\ldots p_r^{e_r}$$

But then this is just a question of the multiplicative order of $p$ modulo $2\hat{n}$ (unless $p=2$, of which, more in the sequel). Since $\gcd(2\hat{n},p)=1$ we have that this is a well-defined notion. So the condition is that if $n=k\cdot o_{2\hat{n}}(p)$ we have the divisibility. Here $o_{2\hat{n}}(p)$ is the multiplicative order of $p$ modulo $2\hat n$. This is a difficult question to settle, in general, since orders of arbitrary elements are hard to compute (this is why finding primitive roots is hard), but certainly if $n=k\phi(2\hat{n})$ is some multiple of the Euler totient function of $2\hat{n}$ then we're in business since $\phi(2\hat{n})$ is the order of the group $\left(\Bbb Z/2\hat{n}\Bbb Z\right)^*$. That number is easily computed as

$$\phi\left(2\hat{n}\right)=\hat{n}\prod_{j=1, j\ne i}^r\left(1-p_j^{-1}\right).$$

Then for $p=2$ it's just a separate computation with the order of $2$ modulo $\hat{n}$ instead of $2\hat{n}$.
So the short answer is:  this is going to be hard to settle in general, since finding orders is a hard thing, and your question is equivalent to that one. However, the upshot is that this means we only really have to check cases for a finite number of primes, namely those which already divide $n$.
So the statement is just

"$2n\big|p^n(p^n-1)$ if and only if, for all primes odd primes $q|n$ we have that $n$ is a multiple of the multiplicative order of $q$ modulo $2\hat{n}$ and for $p=2$ we have that $n$ is a multiple of the order of $2$ modulo $\hat{n}$."

If you look at your example and non-example, we can see this verified. For $n=6$ we have to check $q=2,3$. For $q=2$ we have the order of $2\mod 3$ is $2$, and $2n=12=2\cdot 6$ so that's good; for $q=3$ we have $2\hat{n}=4$ and $3\equiv -1\mod 4$, so its order is $2$, and again $2n=12$ is even, so this works by our criterion. On the other hand for $2n=10$ we have that for $q=2$ the order of $2\mod 5$ is $4$, but $2n$ is not divisible by $4$.