TITLE: Prove n is prime
QUESTION [5 upvotes]: Suppose $n = 2^{m}k +1 $ where m is an integer and k is an odd positive integer less than $2^m$ . Further suppose that there exists an integer $a$ such that $a^{\frac{1}{2}(n-1)}\equiv -1\mod n$. Prove that $n$ must be prime.

I have been stumped on this question for a while. There is an additional hint:

Show first that if $p$ is any prime divisor of $n$ then $ord_p(a)$ must be a divisor of $n-1=2^mk$ and not a divisor of $\frac{1}{2}(n-1) = 2^{m-1}k$, and use Fermat's Little Theorem to deduce that $p\equiv1\mod2^m$.

I'm not even sure how to do the first part of the hint. I have that since $a^n\mod p$ will be periodic, $ord_p(a)|n$. But then doesn't that imply $ord_p(a)|(2^mk+1) \implies2^mk+1\equiv0\mod ord_p(a)$? I thought we were trying to show $2^mk\equiv0\mod ord_p(a)$.
Any help on any part of this question or hint would be greatly appreciated!

REPLY [2 votes]: If $p$ is a prime divisor of $n$ let $\text{ord}_p(a)=x$...... Then $a^{(n-1)/2}\equiv -1 \pmod n$   implies $a^{(n-1)/2 } \equiv -1 \pmod p$  which implies $a^{(n-1)/2} \not \equiv 1 \pmod p$ (because $p$ must be odd) which implies $x \not | (n-1)/2.$.....  But $a^{n-1} \equiv 1 \pmod n$ implies $x|(n-1)=2^m k$ so $x=2^b c$ where $b \le m$ and $c$ is odd (because $k$ is odd) and $c|k.$.... So $y=(n-1)/x=2^{m-b}(k/c)$ is an integer but $y/2$ is not.And because $k/c$ is an odd integer, this requires that $b=m.$.... Hence $2^m c=x=\text{ord}_p(a)|(p-1)$ which implies $ p=2^m j+1$ for some positive integer $j.$..... Now if $n$ is not prime then $ n/p$ is divisible by a prime $p^*$ but then, applying the above argument for $ p^*$ we have$ p^*=2^m j^*+1$ for positive integer $j^*$...... But $k<2^m$ so if $n$ is not prime then $4^m+1>n\ge p p^*>4^m j j^*+1 \ge 4^m+1$ which is absurd. You wrote " $\text{ord_p(a)}|n$ " (after the hint),which is an error.