OFFSET
2,4
COMMENTS
When prime(n)=1 (mod 4), then a(n)=0. When prime(n)=3 (mod 4), then a(n)>0. When prime(n)=3 (mod 8) and prime(n)>3, then 3 divides a(n). See Borevich and Shafarevich. The nonzero terms of this sequence are closely related to A002143, the class number of primes p=3 (mod 4).
Same as difference between the numbers of quadratic residues and nonresidues (mod p) less than p/2, where p=prime(n). - Jonathan Sondow, Oct 30 2011
REFERENCES
Z. I. Borevich and I. R. Shafarevich, Number Theory, Academic Press, NY, 1966, p. 346.
H. Davenport, Multiplicative Number Theory, Graduate Texts in Math. 74, 2nd ed., Springer, 1980, p. 51.
LINKS
R. J. Mathar, Table of n, a(n) for n = 2..2066
MathOverflow, Most squares in the first half-interval
FORMULA
a(n) = sum(j=1..(p-1)/2, (j|p)), where p = prime(n) and (j|p) = +/-1 is the Legendre symbol. - Jonathan Sondow, Oct 30 2011
EXAMPLE
The quadratic residues of 19, the 8th prime, are 1, 4, 5, 6, 7, 9, 11, 16, 17. Hence a(8)=6-3=3.
MAPLE
A178153 := proc(n)
local r, a, p;
p := ithprime(n) ;
a := 0 ;
for r from 1 to p/2 do
if numtheory[legendre](r, p) =1 then
a := a+1 ;
end if;
end do:
for r from ceil(p/2) to p-1 do
if numtheory[legendre](r, p) =1 then
a := a-1 ;
end if;
end do:
a;
end proc: # R. J. Mathar, Feb 10 2017
MATHEMATICA
Table[p=Prime[n]; Length[Select[Range[(p-1)/2], JacobiSymbol[ #, p]==1&]] - Length[Select[Range[(p+1)/2, p-1], JacobiSymbol[ #, p]==1&]], {n, 2, 100}]
Table[p = Prime[n]; Sum[ JacobiSymbol[a, p], {a, 1, (p-1)/2}], {n, 2, 100}] (* Jonathan Sondow, Oct 30 2011 *)
CROSSREFS
KEYWORD
nonn
AUTHOR
T. D. Noe, May 21 2010
STATUS
approved