Determine all positive integers $n$ such that for any positive integer $a$, as long as $\gcd(a, n)=1$, the following one always stands: $$2n^2\mid (a^n-1).$$
To be honest, progress I've achieved on the problem is beneath mention (something like Euler's theorem or Fermat's theorem). It's a hard one.
Please help.
Partial results . . .
Let $S$ be the set of positive integers $n$ such that $$a^n\equiv 1\;(\text{mod}\;2n^2)$$ for all integers $a$, for which $\gcd(a,n)=1$.
If $n=1$, we have $2n^2=2$. Then, using $a=2$, we get $a^n =2^1 = 2$, so $a^n\not\equiv 1\;(\text{mod}\;2n^2)$.
Hence $1 \notin S$.
For a given integer $n > 1$, to test whether $n\in S$, it suffices to verify the congruence $$a^n\equiv 1\;(\text{mod}\;2n^2)$$ for all integers $a$, with $1 < a < n$, for which $\gcd(a,n)=1$.
Applying the above test, we find that each of the integers $2,6,42,1806$ is an element of $S$.
It's conceivable that $S$ has infinitely many elements, but I'm not sure.
What I can prove is this:
Proof:
Let $n\in S$.
Suppose $n$ is odd.
Then letting $a=2$, we have $\gcd(a,n)=1$, hence \begin{align*} &a^n \equiv 1\;(\text{mod}\;2n^2)\\[4pt] \implies\;&2^n \equiv 1\;(\text{mod}\;2n^2)\\[4pt] \implies\;&2^n-1 \equiv 0\;(\text{mod}\;2n^2)\\[4pt] \implies\;&2^n-1 \equiv 0\;(\text{mod}\;2)\\[4pt] \implies\;&2^n-1\;\text{is even}\\[4pt] &\text{contradiction}\\[4pt] \end{align*} Hence $n$ must be even.
Next, suppose $n$ is a multiple of $4$.
Since $n$ is even, we get $n^k \equiv 0\;(\text{mod}\;2n^2)$, for all integers $k \ge 3$.
Let $a=n+1$.$\;$Then $\gcd(a,n)=1$, hence \begin{align*} &a^n\equiv 1\;(\text{mod}\;2n^2)\\[4pt] \implies\;&(n+1)^n \equiv 1\;(\text{mod}\;2n^2)\\[4pt] \implies\;&\left(\sum_{k=0}^{n-3}\binom{n}{k}n^{n-k}\right) + \left({\small{\frac{n(n-1)}{2}}}\right)n^2 + (n)(n) + 1 \equiv 1\;(\text{mod}\;2n^2) \\[4pt] \implies\;& \left({\small{\frac{n(n-1)}{2}}}\right)n^2 + (n)(n) + 1 \equiv 1\;(\text{mod}\;2n^2) \\[4pt] \implies\;& \left({\small{\frac{n(n-1)}{2}}}\right)n^2 + n^2 \equiv 0\;(\text{mod}\;2n^2) \\[4pt] \implies\;&n^2\equiv 0\;(\text{mod}\;2n^2)\qquad\text{[since ${\small{\frac{n(n-1)}{2}}}\;$is even]}\\[4pt] \implies\;&2n^2{\,\mid\,}n^2\\[4pt] &\text{contradiction} \end{align*}
Hence $n$ is even, but not a multiple of $4$, as claimed.
Update:
Checking oeis for the sequence $2,6,42,1806$, we find
$\qquad$https://oeis.org/A014117
which describes a set whose definition is similar, but not exactly the same, as that of $S$.
If, in fact, it can be shown that the oeis set is the same as the set $S$, then it would follow that the integers $2,6,42,1806$ are the only elements of $S$, but I don't see an immediate proof of that claim.