OFFSET
3,1
COMMENTS
The largest nonnegative integer less than n which is not a square modulo n.
If p is a prime congruent 3 modulo 4 then a(p) = p-1 since -1 is not a quadratic residue for such primes.
LINKS
Robert Israel, Table of n, a(n) for n = 3..10000
EXAMPLE
The squares modulo 3 are 0 and 1. Therefore a(3) = 2. The nonsquares modulo 4 are 2 and 3 which makes a(4) = 3. Modulo 5 we have 0, 1 and 4 as squares giving a(5) = 3. 0, 1 and 4 are also the squares modulo 6 resulting in a(6) = 5. Since 10007 is a prime of the form 4*k + 3, a(10007) = 10006.
MAPLE
f:= proc(n) local k;
for k from n-1 by -1 do if numtheory:-msqrt(k, n)=FAIL then return k fi
od
end proc:
map(f, [$3..100]); # Robert Israel, May 14 2020
MATHEMATICA
a[n_] := Module[{r}, For[r = n-1, r >= 1, r--, If[!IntegerQ[Sqrt[Mod[r, n]] ], Return[r]]]];
a /@ Range[3, 100] (* Jean-François Alcover, Aug 15 2020 *)
PROG
(PARI) a(n) = forstep(r = n - 1, 1, -1, if(!issquare(Mod(r, n)), return(r)))
CROSSREFS
KEYWORD
nonn,easy
AUTHOR
Peter Schorn, May 12 2020
STATUS
approved