OFFSET
1,2
LINKS
Daniel Suteu, Table of n, a(n) for n = 1..10000
Wikipedia, Congruence of squares
FORMULA
a(n^2) = n.
a(p) = p - floor(sqrt(p)), for prime p > 2.
EXAMPLE
For n = 10, a(10) = 7, which is the smallest positive integer x such that x^2 mod n is a square and that x^2 >= n. Here 7^2 mod 10 = 9 = 3^2.
MAPLE
a:= proc(n) local k, t;
for k do t:= irem(k^2, n);
if issqr(t) and isqrt(t)<>k then break fi
od; k
end:
seq(a(n), n=1..100); # Alois P. Heinz, Feb 01 2019
MATHEMATICA
a[n_] := For[x = Sqrt[n]//Ceiling, True, x++, If[IntegerQ[Sqrt[PowerMod[x, 2, n]]], Return[x]]];
Array[a, 100] (* Jean-François Alcover, Nov 07 2020 *)
PROG
(PARI) a(n) = for(k=sqrtint(n), oo, if(issquare(k^2 % n) && sqrtint(k^2 % n) != k, return(k)));
CROSSREFS
KEYWORD
nonn
AUTHOR
Daniel Suteu, Feb 01 2019
STATUS
approved