%I #146 Sep 02 2024 01:12:48
%S 1,0,2,-1,2,0,2,-2,3,0,2,-2,2,0,4,-3,2,0,2,-2,4,0,2,-4,3,0,4,-2,2,0,2,
%T -4,4,0,4,-3,2,0,4,-4,2,0,2,-2,6,0,2,-6,3,0,4,-2,2,0,4,-4,4,0,2,-4,2,
%U 0,6,-5,4,0,2,-2,4,0,2,-6,2,0,6,-2,4,0,2,-6,5,0,2,-4,4,0,4,-4,2,0,4,-2,4
%N Number of odd divisors of n minus number of even divisors of n.
%C abs(a(n)) = (1/2) * (number of pairs (i,j) satisfying n = i^2 - j^2 and -n <= i,j <= n). - _Benoit Cloitre_, Jun 14 2003
%C As A001227(n) is the number of ways to write n as the difference of 3-gonal numbers, a(n) describes the number of ways to write n as the difference of e-gonal numbers for e in {0,1,4,8}. If pe(n):=(1/2)*n*((e-2)*n+(4-e)) is the n-th e-gonal number, then 4*a(n) = |{(m,k) of Z X Z; pe(-1)(m+k)-pe(m-1)=n}| for e=1, 2*a(n) = |{(m,k) of Z X Z; pe(-1)(m+k)-pe(m-1)=n}| for e in {0,4} and for a(n) itself is a(n) = |{(m,k) of Z X Z; pe(-1)(m+k)-pe(m-1)=n}| for e=8. (Same for e=-1 see A035218.) - Volker Schmitt (clamsi(AT)gmx.net), Nov 09 2004
%C An argument by _Gareth McCaughan_ suggests that the average of this sequence is log(2). - _Hans Havermann_, Feb 10 2013 [Supported by a graph. - _Vaclav Kotesovec_, Mar 01 2023]
%C From _Keith F. Lynch_, Jan 20 2024: (Start)
%C a(n) takes every possible integer value, positive, negative, and zero. Proof: For all nonnegative integers k, a(3^k) = 1+k, a(2^k) = 1-k.
%C a(n) takes every possible integer value except 1 and -1 infinitely many times. Proof: a(o^(k-1)) = k and a(4*o^(k-1)) = -k for all positive integers k and odd primes o, of which there are infinitely many. a(n) = 0 iff n = 2 (mod 4). a(n) = 1 iff n = 1. a(n) = -1 iff n = 4.
%C a(n) takes prime value p only for n = o^(p-1), where o is any odd prime.
%C Terms have a simple pattern that repeats with a period of 4: Positive, zero, positive, negative.
%C (End)
%C Inverse Möbius transform of (-1)^(n+1). - _Wesley Ivan Hurt_, Jun 22 2024
%D Louis Comtet, Advanced Combinatorics, Reidel, 1974, p. 162, #16, (6), first formula.
%D S. Ramanujan, Notebooks, Tata Institute of Fundamental Research, Bombay 1957 Vol. 1, see page 97, 7(ii).
%H T. D. Noe, <a href="/A048272/b048272.txt">Table of n, a(n) for n = 1..10000</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 Vaclav Kotesovec, <a href="/A048272/a048272.jpg">Plot of Sum_{k=1..n} a(k) / n, for n = 1..1000000</a>
%H P. A. MacMahon, <a href="http://dx.doi.org/10.1112/plms/s2-19.1.75">Divisors of numbers and their continuations in the theory of partitions</a>, Proc. London Math. Soc., 19 (1921), 75-113; Coll. Papers II, pp. 303-341.
%H Mircea Merca, <a href="http://dx.doi.org/10.1016/j.jnt.2015.08.014">Combinatorial interpretations of a recent convolution for the number of divisors of a positive integer</a>, Journal of Number Theory, Volume 160, March 2016, Pages 60-75, function tau_{o-e}(n).
%H <a href="/index/Ge#Glaisher">Index entries for sequences mentioned by Glaisher</a>.
%F Coefficients in expansion of Sum_{n >= 1} x^n/(1+x^n) = Sum_{n >= 1} (-1)^(n-1)*x^n/(1-x^n). Expand Sum 1/(1+x^n) in powers of 1/x.
%F If n = 2^p1*3^p2*5^p3*7^p4*11^p5*..., a(n) = (1-p1)*Product_{i>=2} (1+p_i).
%F Multiplicative with a(2^e) = 1 - e and a(p^e) = 1 + e if p > 2. - _Vladeta Jovovic_, Jan 27 2002
%F a(n) = (-1)*Sum_{d|n} (-1)^d. - _Benoit Cloitre_, May 12 2003
%F Moebius transform is period 2 sequence [1, -1, ...]. - _Michael Somos_, Jul 22 2006
%F G.f.: Sum_{k>0} -(-1)^k * x^(k^2) * (1 + x^(2*k)) / (1 - x^(2*k)) [Ramanujan]. - _Michael Somos_, Jul 22 2006
%F Equals A051731 * [1, -1, 1, -1, 1, ...]. - _Gary W. Adamson_, Nov 07 2007
%F From _Reinhard Zumkeller_, Jan 21 2012: (Start)
%F a(n) = A001227(n) - A183063(n).
%F a(A008586(n)) < 0; a(A005843(n)) <= 0; a(A016825(n)) = 0; a(A042968(n)) >= 0; a(A005408(n)) > 0. (End)
%F a(n) = Sum_{k=0..n} A081362(k)*A015723(n-k). - _Mircea Merca_, Feb 26 2014
%F abs(a(n)) = A112329(n) = A094572(n) / 2. - _Ray Chandler_, Aug 23 2014
%F From _Peter Bala_, Jan 07 2015: (Start)
%F Logarithmic g.f.: log( Product_{n >= 1} (1 + x^n)^(1/n) ) = Sum_{n >= 1} a(n)*x^n/n.
%F a(n) = A001227(n) - A183063(n). By considering the logarithmic generating functions of these three sequences we obtain the identity
%F ( Product_{n >= 0} (1 - x^(2*n+1))^(1/(2*n+1)) )^2 = Product_{n >= 1} ( (1 - x^n)/(1 + x^n) )^(1/n). (End)
%F Dirichlet g.f.: zeta(s)*eta(s) = zeta(s)^2*(1-2^(-s+1)). - _Ralf Stephan_, Mar 27 2015
%F a(2*n - 1) = A099774(n). - _Michael Somos_, Aug 12 2017
%F From _Paul D. Hanna_, Aug 10 2019: (Start)
%F G.f.: Sum_{n>=0} x^n * Sum_{k=0..n} binomial(n,k) * (x^(n+1) - x^k)^(n-k) = Sum_{n>=0} a(n)*x^(2*n).
%F G.f.: Sum_{n>=0} x^n * Sum_{k=0..n} binomial(n,k) * (x^(n+1) + x^k)^(n-k) * (-1)^k = Sum_{n>=0} a(n)*x^(2*n). (End)
%F a(n) = 2*A000005(2n) - 3*A000005(n). - _Ridouane Oudra_, Oct 15 2019
%F Limit_{m->oo} (1/m) * Sum_{k=1..m} a(k)/A000005(k) = 2*log(2)-1. - _Amiram Eldar_, Mar 01 2023
%e a(20) = -2 because 20 = 2^2*5^1 and (1-2)*(1+1) = -2.
%e G.f. = x + 2*x^3 - x^4 + 2*x^5 + 2*x^7 - 2*x^8 + 3*x^9 + 2*x^11 - 2*x^12 + ...
%p add(x^n/(1+x^n), n=1..60): series(%,x,59);
%p A048272 := proc(n)
%p local a;
%p a := 1 ;
%p for pfac in ifactors(n)[2] do
%p if pfac[1] = 2 then
%p a := a*(1-pfac[2]) ;
%p else
%p a := a*(pfac[2]+1) ;
%p end if;
%p end do:
%p a ;
%p end proc: # Schmitt, sign corrected _R. J. Mathar_, Jun 18 2016
%p # alternative Maple program:
%p a:= n-> -add((-1)^d, d=numtheory[divisors](n)):
%p seq(a(n), n=1..100); # _Alois P. Heinz_, Feb 28 2018
%t Rest[ CoefficientList[ Series[ Sum[x^k/(1 - (-x)^k), {k, 111}], {x, 0, 110}], x]] (* _Robert G. Wilson v_, Sep 20 2005 *)
%t dif[n_]:=Module[{divs=Divisors[n]},Count[divs,_?OddQ]-Count[ divs, _?EvenQ]]; Array[dif,100] (* _Harvey P. Dale_, Aug 21 2011 *)
%t a[n]:=Sum[-(-1)^d,{d,Divisors[n]}] (* _Steven Foster Clark_, May 04 2018 *)
%t f[p_, e_] := If[p == 2, 1 - e, 1 + e]; a[n_] := Times @@ f @@@ FactorInteger[n]; a[1] = 1; Array[a, 100] (* _Amiram Eldar_, Jun 09 2022 *)
%o (PARI) {a(n) = if( n<1, 0, -sumdiv(n, d, (-1)^d))}; /* _Michael Somos_, Jul 22 2006 */
%o (PARI)
%o N=17; default(seriesprecision,N); x=z+O(z^(N+1))
%o c=sum(j=1,N,j*x^j); \\ log case
%o s=-log(prod(j=1,N,(1+x^j)^(1/j)));
%o s=serconvol(s,c)
%o v=Vec(s) \\ _Joerg Arndt_, May 03 2008
%o (PARI) a(n)=my(o=valuation(n,2),f=factor(n>>o)[,2]);(1-o)*prod(i=1,#f,f[i]+1) \\ _Charles R Greathouse IV_, Feb 10 2013
%o (PARI) a(n)=direuler(p=1,n,if(p==2,(1-2*X)/(1-X)^2,1/(1-X)^2))[n] /* _Ralf Stephan_, Mar 27 2015 */
%o (PARI) {a(n) = my(d = n -> if(frac(n), 0, numdiv(n))); if( n<1, 0, if( n%4, 1, -1) * (d(n) - 2*d(n/2) + 2*d(n/4)))}; /* _Michael Somos_, Aug 11 2017 */
%o (Haskell)
%o a048272 n = a001227 n - a183063 n -- _Reinhard Zumkeller_, Jan 21 2012
%o (Magma) [&+[(-1)^(d+1):d in Divisors(n)] :n in [1..95] ]; // _Marius A. Burtea_, Aug 10 2019
%Y Cf. A048298. A diagonal of A060184.
%Y First differences of A059851.
%Y Cf. A001227, A035218, A094572, A099774, A112329, A183063, A000005.
%Y Indices of records: A053624 (highs), A369151 (lows).
%K easy,sign,nice,mult
%O 1,3
%A _Adam Kertesz_
%E New definition from _Vladeta Jovovic_, Jan 27 2002