Created
February 16, 2026 14:13
-
-
Save Hermann-SW/b4d422842b22da4d5f2838a211f38e02 to your computer and use it in GitHub Desktop.
Sequential determination of primitive root of n-th Euclid prime
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| euclid_prime_find_root(n) = { | |
| my(En = vecprod(primes(n)) + 1, phi = En - 1); | |
| for(g=2, En-1, | |
| if(lift(kronecker(g, En))==-1, | |
| my(is_root = 1); | |
| for(i=1, n, | |
| if(lift(Mod(g, En)^(phi / prime(i))) == 1, | |
| is_root = 0; | |
| break; | |
| ); | |
| ); | |
| if(is_root, return(g)); | |
| ); | |
| ); | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Demonstration on 457th Euclid prime,
and demonstration of huge speedup over GP znprimroot() (which has to factor N-1 first):
Parallelized in par2.gp gist: