%I #34 Nov 25 2023 20:57:26
%S 1,2,3,2,3,5,3,5,2,5,3,7,2,6,7,8,2,6,7,11,3,5,3,5,6,7,10,11,12,14,5,
%T 11,2,3,10,13,14,15,7,13,17,19,5,7,10,11,14,15,17,19,20,21,2,3,8,12,
%U 13,17,22,23,7,11,15,19,2,5,11,14,20,23,2,3,8,10,11,14,15,18,19,21,26
%N Triangle read by rows in which row n lists the primitive roots mod n (omitting numbers n without a primitive root).
%H T. D. Noe, <a href="/A046147/b046147.txt">Table of n, a(n) for n = 2..3119</a> (first 99 nonempty rows of triangle, flattened)
%H Eric Weisstein's World of Mathematics, <a href="http://mathworld.wolfram.com/PrimitiveRoot.html">Primitive Root.</a>
%e n followed by primitive roots, if any:
%e 1 -
%e 2 1
%e 3 2
%e 4 3
%e 5 2 3
%e 6 5
%e 7 3 5
%e 8 -
%e 9 2 5
%e 10 3 7
%e 11 2 6 7 8
%e 12 -
%e 13 2 6 7 11
%e ...
%p f:= proc(n) local p,k,m,R;
%p p:= numtheory:-primroot(n);
%p if p = FAIL then return NULL fi;
%p m:= numtheory:-phi(n);
%p k:= select(i -> igcd(i,m) = 1, [$1..m-1]);
%p op(sort(map(t -> p&^t mod n, k)))
%p end proc:
%p f(2):= 1:
%p map(f, [$2..50]); # _Robert Israel_, Apr 28 2017
%t a[n_] := Select[Range[n-1], GCD[#, n] == 1 && MultiplicativeOrder[#, n] == EulerPhi[n]& ]; Table[a[n], {n, 1, 30}] // Flatten (* _Jean-François Alcover_, Oct 23 2012 *)
%t PrimitiveRootList[Range[Prime[10]]]//Flatten (* Requires Mathematica version 10 or later *) (* _Harvey P. Dale_, Sep 10 2016 *)
%o (PARI) a_row(r) = my(v=[], phi=eulerphi(r)); for(i=1, r-1, if(1 == gcd(r, i) && phi == znorder(Mod(i, r)), v=concat(v, i))); v \\ _Ruud H.G. van Tol_, Oct 23 2023
%Y Cf. A001918, A046144 (row lengths), A046145, A046146.
%Y Cf. A060749, A306252 (1st column), A306253 (last/maximum element)
%K nonn,tabf
%O 2,2
%A _Eric W. Weisstein_
%E Edited by _Robert Israel_, Apr 28 2017