primroot | R Documentation |
Find the smallest primitive root modulo m, or find all primitive roots.
primroot(m, all = FALSE)
m |
A prime integer. |
all |
boolean; shall all primitive roots module p be found. |
For every prime number m there exists a natural number n that generates the field F_m, i.e. n, n^2, ..., n^{m-1} mod (m) are all different.
The computation here is all brute force. As most primitive roots are relatively small, so 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.
A natural number if m
is prime, else NA
.
This function is not vectorized.
Arndt, J. (2010). Matters Computational: Ideas, Algorithms, Source Code. Springer-Verlag, Berlin Heidelberg Dordrecht.
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.