Given a prime $p$ and number $a$, how do I find the smallest $n$ such that $n^a\equiv 1 \pmod p$? Is there a non trial-and-error method?
Edit: obviously removing $n=1$!
Given a prime $p$ and number $a$, how do I find the smallest $n$ such that $n^a\equiv 1 \pmod p$? Is there a non trial-and-error method?
Edit: obviously removing $n=1$!
The Tonelli-Shanks and Cipolla algorithms for square-roots can easily be generalized to compute d'th roots in finite fields, e.g. see Adleman; Manders; Miller: On taking roots in finite fields, and Bach; Shallit: Algorithmic number theory, section 7.3. See also this answer.
I haven't yet found an example where $n \not\equiv 1$, $a=3$, and $\gcd(p-1,3) = 1$. So I suspect nontrivial answers only exist when $\gcd(p-1,3) \ne 1$.
When $\gcd(a,p-1) = k \ne 1$, we have $\forall n \not\equiv 0, n^{\frac{a(p-1)}{k}} = \left(n^{\frac{a}{k}}\right)^{p-1} \equiv 1$, so $\forall n \not\equiv 0, \left(n^{\frac{p-1}{k}}\right)^a \equiv 1$.
This suggests an algorithm where you search for the smallest $\frac{p-1}{k}$th power, but I'm not sure how you'd go about that.