powered by
primroot(m)
m
NA
The computation here is all brute force. As most primitive roots are relatively small, it is still reasonable fast.
One trick is to factorize $m-1$ and test only for those prime factors. In R this is not more efficient as factorization also takes some time.
modpower
modorder
P <- primes(100) R <- c() for (p in P) { R <- c(R, primroot(p)) } cbind(P, R) # 7 is the biggest prime root here (for p=71)
Run the code above in your browser using DataLab