Let n be an odd natural (positive) number such that $3 \nmid n$.
It is further given that:
- $3^{\frac{n-1}{2}} \equiv -1 \pmod{n}$
- The order of 9 modulo n is $\frac{n-1}{2}$
Prove that n must be prime.
I went about it in the following way, which seems to work, however I'm not making full use of both given facts which makes me suspect I got something wrong or otherwise the problem statement is redundant.
My solution:
we know n is odd, and therefore n-1 is even, and n is not a multiple of 3. Therefore, we can use 1. above to deduce that $3^{n-1} \equiv (3^{\frac{n-1}{2}})^2 \equiv 1 \pmod{n}$. The order of any number relatively prime to n must divide $\phi(n)$ therefore $\phi(n) = k \cdot (n-1)$.
Now we can use a property of Euler's phi function which is that $\phi(n) \leq n - \sqrt{n}$ for every n which is composite. But we have $\phi(n) = k \cdot (n-1) \geq n-1 > n - \sqrt{n}$ , which holds in our case and therefore n is necessarily prime, QED.
Is this right?
The error that you made is that even though $3^{n-1} \equiv 1 \pmod{n}$, the order of 3 mod n need not be $n-1$. This is because the order is the smallest $k$ that satisfies $3^k \equiv 1 \pmod{n}$, and you've not checked that there are no smaller solutions (other than checking $ \frac{n-1}{2}$).
Thus, even though "The order of any number relatively prime to n must divide $\phi(n)$" is true, the statement "$\phi(n) = k(n-1)$ is not true.
Proof of the question
Note: We still have no control over the order of $3$, other than being a divisor of $n-1$ but not a divisor of $\frac{n-1}{2}$. For example, it could theoretically be $\frac{n-1}{3}$. OP continually makes an error of not allowing this possibility.