login
Largest prime primitive root of n that is less than n, or 0 if none exists.
6

%I #17 Feb 16 2025 08:32:56

%S 0,0,0,2,3,3,5,5,0,5,7,7,0,11,5,0,0,11,11,13,0,0,19,19,0,23,19,23,0,

%T 19,0,17,0,0,31,0,0,19,29,0,0,29,0,29,0,0,43,43,0,47,47,0,0,41,47,0,0,

%U 0,47,47,0,59,53,0,0,0,0,61,0,0,0,67,0,59,61,0,0,0,0,59,0,59,71,79,0,0,73

%N Largest prime primitive root of n that is less than n, or 0 if none exists.

%H Robert Israel, <a href="/A103310/b103310.txt">Table of n, a(n) for n = 0..10000</a>

%H Eric Weisstein's World of Mathematics, <a href="https://mathworld.wolfram.com/PrimitiveRoot.html">Primitive Root</a>.

%p hasproot:= proc(n)

%p if n::odd then nops(numtheory:-factorset(n))=1

%p else padic:-ordp(n,2)=1 and nops(numtheory:-factorset(n/2))=1

%p fi

%p end proc;

%p hasproot(2):= true: hasproot(4):= true:

%p f:= proc(n) local p,t;

%p if not hasproot(n) then return 0 fi;

%p t:= numtheory:-phi(n);

%p p:= prevprime(n);

%p while not numtheory:-order(p,n)=t do

%p if p = 2 then return 0 fi;

%p p:= prevprime(p);

%p od;

%p p

%p end proc:

%p f(0):= 0: f(1):= 0: f(2):= 0:

%p map(f, [$0..100]); # _Robert Israel_, Sep 08 2020

%t a[n_] := Module[{R = PrimitiveRootList[n], s}, s = Select[R, # < n && PrimeQ[#]&]; If[s == {}, 0, s[[-1]]]];

%t Table[a[n], {n, 0, 100}] (* _Jean-François Alcover_, Feb 01 2023 *)

%Y Cf. A001918, A046144, A046145, A046146, A103309.

%K easy,nonn,changed

%O 0,4

%A _Harry J. Smith_, Jan 29 2005