OFFSET
3,3
COMMENTS
a(n) is the distance between n and the largest quadratic nonresidue modulo n: a(n) = n - A334819(n). So n - a(n) is the largest nonsquare modulo n.
LINKS
Amiram Eldar, Table of n, a(n) for n = 3..10000
EXAMPLE
The nonsquares modulo 8 are 2, 3, 5, 6, and 7, so the distance of the largest quadratic nonresidue from 8 is a(8) = 1. The quadratic nonresidues modulo 17 are 3, 5, 6, 7, 10, 11, 12, and 14, so a(17) = 17 - 14 = 3.
MATHEMATICA
a[n_] := n - Max @ Complement[Range[n - 1], Mod[Range[n/2]^2, n]]; Array[a, 100, 3] (* Amiram Eldar, Jun 15 2022 *)
PROG
(PARI) a(n) = forstep(r = n - 1, 1, -1, if(!issquare(Mod(r, n)), return(n-r))) \\ Thomas Scheuerle, Jun 15 2022
CROSSREFS
KEYWORD
nonn,easy
AUTHOR
Joel Brennan, Jun 14 2022
STATUS
approved