%I #36 Sep 27 2023 02:43:54
%S 1,1,-2,1,6,-2,-6,1,7,6,-10,-2,14,-6,-12,1,18,7,-18,6,12,-10,-22,-2,
%T 31,14,-20,-6,30,-12,-30,1,20,18,-36,7,38,-18,-28,6,42,12,-42,-10,42,
%U -22,-46,-2,43,31,-36,14,54,-20,-60,-6,36,30,-58,-12,62,-30,-42,1,84,20,-66,18,44,-36,-70
%N a(n) = Sum_{ d divides n, d==1 mod 4} d - Sum_{ d divides n, d==3 mod 4} d.
%C Multiplicative because it is the Inverse Moebius transform of [1 0 -3 0 5 0 -7 ...], which is multiplicative. - _Christian G. Bower_, May 18 2005
%H Indranil Ghosh, <a href="/A050457/b050457.txt">Table of n, a(n) for n = 1..5000</a>
%H J. W. L. Glaisher, <a href="https://books.google.com/books?id=bLs9AQAAMAAJ&pg=RA1-PA1">On the representations of a number as the sum of two, four, six, eight, ten, and twelve squares</a>, Quart. J. Math. 38 (1907), 1-62 (see p. 4 and p. 8).
%H <a href="/index/Ge#Glaisher">Index entries for sequences mentioned by Glaisher</a>.
%F a(n) is multiplicative with a(p^e)=1 if p=2, a(p^e)=(p^(e+1)-1)/(p-1) if p == 1 (mod 4), a(p^e)=((-p)^(e+1)-1)/(-p-1) if p == 3 (mod 4). - _Michael Somos_, May 29 2005
%F G.f.: Sum_{k>=1} (-1)^(k-1)*(2*k - 1)*x^(2*k-1)/(1 - x^(2*k-1)). - _Ilya Gutkovskiy_, Dec 22 2018
%F a(n) = Im(Sum_{d|n} d*i^d). - _Ridouane Oudra_, Feb 02 2020
%F a(n) = Sum_{d|n} d*sin(d*Pi/2). - _Ridouane Oudra_, Feb 18 2023
%p with(numtheory):
%p A050457 := proc(n)
%p local count1, count3, d;
%p count1 := 0:
%p count3 := 0:
%p for d in numtheory[divisors](n) do
%p if d mod 4 = 1 then
%p count1 := count1+d
%p elif d mod 4 = 3 then
%p count3 := count3+d
%p fi:
%p end do:
%p count1-count3;
%p end proc: # _Ridouane Oudra_, Feb 02 2020
%p # second Maple program:
%p a:= n-> add(`if`(d::odd, d*(-1)^((d-1)/2), 0), d=numtheory[divisors](n)):
%p seq(a(n), n=1..100); # _Alois P. Heinz_, Feb 03 2020
%t Table[Sum[KroneckerSymbol[-4, d] d , {d, Divisors[n]}], {n, 71}] (* _Indranil Ghosh_, Mar 16 2017 *)
%t f[p_, e_] := If[Mod[p, 4] == 1, (p^(e+1)-1)/(p-1), ((-p)^(e+1)-1)/(-p-1)]; f[2, e_] := 1; a[1] = 1; a[n_] := Times @@ f @@@ FactorInteger[n]; Array[a, 100] (* _Amiram Eldar_, Sep 27 2023 *)
%o (PARI) {a(n)=local(A,p,e); if(n<1, 0, A=factor(n); prod(k=1,matsize(A)[1], if(p=A[k,1], e=A[k,2]; if(p==2, 1, p*=kronecker(-4,p); (p^(e+1)-1)/(p-1)))))} /* _Michael Somos_, May 29 2005 */
%o (PARI) {a(n)=if(n<1, 0, sumdiv(n, d, kronecker(-4, d)*d))} /* _Michael Somos_, May 29 2005 */
%Y Column k=1 of A322143.
%K sign,easy,mult
%O 1,3
%A _N. J. A. Sloane_, Dec 23 1999