Aks algorithm has a lemma as follows
$$\text{n is prime} \iff (x+a)^n \equiv x^n + a \mod n$$
where $a \in \mathbb{Z} \land (a,n)=1, n\in \mathbb{N}-\{1\}$ and $x$ is an independent variable
For completeness I am presenting the proof of the above lemma, which has the following two parts
$$\text{n is prime} \implies (x+a)^n \equiv x^n + a \mod n$$
If $n$ is prime then $\binom{n}{r} \equiv 0 \mod n $ for $1 \le r \le n-1$
Hence first part is true
$$ (x+a)^n \equiv x^n + a \mod n \implies \text{n is prime}$$
Suppose if $n$ is composite and $k$ is the largest natural number such that $q^k | n$ for a prime factor $q|n$, then $q^k \not| \binom{n}{q}$ and hence $ \binom{n}{q}a^{n-q} \not\equiv 0 \mod n$
Here is my doubt
If we restrict the independent variable $x$ to the natural domain, the first part holds i.e,.
$$\text{n is prime} \implies (x+a)^n \equiv x^n + a \mod n$$
What about the second part?
$$ (x+a)^n \equiv x^n + a \mod n \implies \text{n is prime}$$
Does it holds true if $(x,n)=1$?
let $(x,n)=1$, then $\binom{n}{q} x^q a^{n-q} \not \equiv 0 \mod n$, but can we say that second part holds even for all $x$, such that $(x,n)=1$
To put it in short
For what values of $x \in \mathbb{N},$ the second part of the lemma satisfies
$$$$