OFFSET
0,4
LINKS
Robert Israel, Table of n, a(n) for n = 0..10000
Eric Weisstein's World of Mathematics, Primitive Root.
MAPLE
hasproot:= proc(n)
if n::odd then nops(numtheory:-factorset(n))=1
else padic:-ordp(n, 2)=1 and nops(numtheory:-factorset(n/2))=1
fi
end proc;
hasproot(2):= true: hasproot(4):= true:
f:= proc(n) local p, t;
if not hasproot(n) then return 0 fi;
t:= numtheory:-phi(n);
p:= prevprime(n);
while not numtheory:-order(p, n)=t do
if p = 2 then return 0 fi;
p:= prevprime(p);
od;
p
end proc:
f(0):= 0: f(1):= 0: f(2):= 0:
map(f, [$0..100]); # Robert Israel, Sep 08 2020
MATHEMATICA
a[n_] := Module[{R = PrimitiveRootList[n], s}, s = Select[R, # < n && PrimeQ[#]&]; If[s == {}, 0, s[[-1]]]];
Table[a[n], {n, 0, 100}] (* Jean-François Alcover, Feb 01 2023 *)
CROSSREFS
KEYWORD
easy,nonn
AUTHOR
Harry J. Smith, Jan 29 2005
STATUS
approved