We can use the Lucas test to find all the primitive roots of p as in the following program:
#include <lnv3/lnv3.h>
#include <nttl/gcd.h>
#include <nttl/randomPrime.h>
#include <nttl/inverse.h>
#include <stdio.h>
main(int argc, char** argv){
ln x, p,p_1,q;
int i,prime=11;
prime = ((argc > 1) ? atoi(argv[1]):prime);
p = (ln) prime;
p_1 = p -1;
bool test;
for(x=1 ; x < p; x++){
test = true;
for(i=2; i < p;i++){
if(p_1 % i == 0){
q = p_1/i;
if(x.FastExp(q,p)== 1) {test=false;break;}
}
}
if(test) cout<< x << " is a primitive root" <<endl;
}
}
So, the primitive roots for 11 are {2,6,7,8}. The primitive roots for 23
are
{5,7,10,11,14,15,17,19,20,21}.