OFFSET
1,1
COMMENTS
LINKS
Robert Israel, Table of n, a(n) for n = 1..4000
Christian Aebi and Grant Cairns, Sums of Quadratic residues and nonresidues, arXiv:1512.00896 [math.NT], 2015.
MAPLE
with(numtheory):
Ql:=[]; Qu:=[]; Q:=[]; Nl:=[]; Nu:=[]; N:=[]; Th:=[];
for i1 from 1 to 300 do
p:=ithprime(i1);
if (p mod 8) = 3 then
ql:=0; qu:=0; q:=0; nl:=0; nu:=0; n:=0;
for j from 1 to p-1 do
if legendre(j, p)=1 then
q:=q+j;
if j<p/2 then ql:=ql+j; else qu:=qu+j; fi;
else
n:=n+j;
if j<p/2 then nl:=nl+j; else nu:=nu+j; fi;
fi;
od;
Ql:=[op(Ql), ql];
Qu:=[op(Qu), qu];
Q:=[op(Q), q];
Nl:=[op(Nl), nl];
Nu:=[op(Nu), nu];
N:=[op(N), n];
Th:=[op(Th), q+ql];
fi;
od:
# Alternative:
v:= proc(x, r) if x <= r then 2*x else x fi end proc:
f:= proc(p) local q, r, j;
r:= (p-1)/2;
add(v(j^2 mod p, r), j=1..r)
end proc:
map(f, select(isprime, [seq(i, i=3..1000, 8)])); # Robert Israel, Mar 27 2017
MATHEMATICA
v[x_, r_] := If[x <= r, 2*x, x];
f[p_] := Module[{r}, r = (p-1)/2; Sum[v[PowerMod[j, 2, p], r], {j, 1, r}]];
f /@ Select[Range[3, 1000, 8], PrimeQ] (* Jean-François Alcover, Nov 27 2017, after Robert Israel *)
PROG
(Python)
from sympy import isprime
def v(x, r):
return 2*x if x<=r else x
def a(p):
r=(p - 1)//2
return sum(v((j**2)%p, r) for j in range(1, r + 1))
print([a(p) for p in range(3, 2001, 8) if isprime(p)]) # Indranil Ghosh, Mar 27 2017 translated from Robert Israel's Maple program
CROSSREFS
KEYWORD
nonn
AUTHOR
N. J. A. Sloane, Feb 20 2017
STATUS
approved