A variation of Fermat's Little Theorem Can we find a general $n$ where the following expression holds for all $a$ :
$$a^{n+1} \equiv a \pmod n$$
I have tried it by using Fermat's theorem and even arrived at it for $n=2$ as
$$a^{3}\equiv a \pmod 2$$
I have also tried using Wilson's theorem
$$(p-1)!\equiv -1 \pmod p$$
to see if I can replace $(p-1)!$ by $a$ but am stuck here!
 A: I thought the only $n$ that this holds is $n=2$, but it wasn't.
First suppose that $n$ is not square-free. Then there exists some prime $p$ such that $p^2 \mid n$.
We now have $p^{n+1} \equiv 0 \pmod {p^2}$, so $p \not\equiv p^{n+1} \pmod {p^2}$.
This shows that $p^{n+1} \not\equiv p \pmod n$, which implies that $n$ must be square-free.
Hence $n$ is a product of distinct primes, and suppose for a prime $p$, $p \mid n$.
We have, by FLT, $a^p \equiv a \pmod p$.
Hence $a^{n+1} = a^{p (n/p)+1} \equiv a \cdot a^{n/p} \pmod p$, and we want to find $n$ such that:
$$a^{n/p} \equiv 1 \pmod p \text{ for all } p \nmid a \text{ and } p \mid n$$
By the existence of primitive roots, we can find $a'$ such that the multiplicative order of $a'$ is precisely $p-1$.
Thus we require $(p-1) \mid \dfrac n p$. By $\gcd (p,p-1)=1$, this is equivalent to showing that $(p-1) \mid n$.
I do not know how many numbers are there that satisfy the equation, but $42$ does:
$$42 = 2 \times 3 \times 7\text{ , and }1,2,6 \mid 42$$
and we do have $a^{43} \equiv a \pmod {42}$ for all $a$.
Easier examples include $n=2$ (trivial) and $n=6$ (not quite trivial). And also $1806$ as well.
EDIT: Found this on OEIS: A014117. There are no more. A (short) proof that this is finite is also in the [LINKS] section, compiled by Don Reble.
