login
Number of partitions of n into 3 squares (allowing part zero).
28

%I #44 Oct 17 2022 01:45:44

%S 1,1,1,1,1,1,1,0,1,2,1,1,1,1,1,0,1,2,2,1,1,1,1,0,1,2,2,2,0,2,1,0,1,2,

%T 2,1,2,1,2,0,1,3,1,1,1,2,1,0,1,2,3,2,1,2,3,0,1,2,1,2,0,2,2,0,1,3,3,1,

%U 2,2,1,0,2,2,3,2,1,2,1,0,1,4,2,2,1,2,3,0,1,4,3,1,0,1,2,0,1,2,3,3,2,4,2,0,2

%N Number of partitions of n into 3 squares (allowing part zero).

%C a(n) = number of triples of integers [ i, j, k] such that i >= j >= k >= 0 and n = i^2 + j^2 + k^2. - _Michael Somos_, Jun 05 2012

%D E. Grosswald, Representations of Integers as Sums of Squares. Springer-Verlag, NY, 1985, p. 84.

%H T. D. Noe, <a href="/A000164/b000164.txt">Table of n, a(n) for n = 0..10000</a>

%H Hirschhorn, M. D., <a href="http://dx.doi.org/10.1016/S0012-365X(99)00159-4">Some formulas for partitions into squares</a>, Discrete Math. 211 (2000), pp. 225-228.

%F Let e(n,r,s,m) be the excess of the number of n's r(mod m) divisors over the number of its s (mod m) divisors, and let delta(n)=1 if n is a perfect square and 0 otherwise. Then, if we define alpha(n) = 5*delta(n) + 3*delta(n/2) + 4*delta(n/3), beta(n) = 4*e(n,1,3,4) + 3*e(n,1,7,8) + 3*e(n,3,5,8), gamma(n) = 2*Sum_{1<=k^2<n} e(n-k^2,1,3,4), it follows that a(n) = (1/12)*(alpha(n) + beta(n) + gamma(n)). - _Ant King_, Oct 15 2010

%e G.f. = 1 + x + x^2 + x^3 + x^4 + x^5 + x^6 + x^8 + 2*x^9 + x^10 + x^11 + x^12 + x^13 + ...

%p A000164 := proc(n)

%p local a,x,y,z2,z ;

%p a := 0 ;

%p for x from 0 do

%p if 3*x^2 > n then

%p return a;

%p end if;

%p for y from x do

%p if x^2+2*y^2 > n then

%p break;

%p end if;

%p z2 := n-x^2-y^2 ;

%p if issqr(z2) then

%p z := sqrt(z2) ;

%p if z >= y then

%p a := a+1 ;

%p end if;

%p end if;

%p end do:

%p end do:

%p a;

%p end proc: # _R. J. Mathar_, Feb 12 2017

%t Length[PowersRepresentations[ #, 3, 2]] & /@ Range[0, 104]

%t e[0,r_,s_,m_]=0;e[n_,r_,s_,m_]:=Length[Select[Divisors[n],Mod[ #,m]==r &]]-Length[Select[Divisors[n],Mod[ #,m]==s &]];alpha[n_]:=5delta[n]+3delta[1/2 n]+4delta[1/3n];beta[n_]:=4e[n,1,3,4]+3e[n,1,7,8]+3e[n,3,5,8];delta[n_]:=If[IntegerQ[Sqrt[n]],1,0];f[n_]:=Table[n-k^2, {k,1,Floor[Sqrt[n]]}]; gamma[n_]:=2 Plus@@(e[ #,1,3,4] &/@f[n]);p3[n_]:=1/12(alpha[n]+beta[n]+gamma[n]);p3[ # ] &/@Range[0,104]

%t (* _Ant King_, Oct 15 2010 *)

%t a[ n_] := If[ n < 0, 0, Sum[ Boole[ n == i^2 + j^2 + k^2], {i, 0, Sqrt[n]}, {j, 0, i}, {k, 0, j}]]; (* _Michael Somos_, Aug 15 2015 *)

%o (PARI) {a(n) = if( n<0, 0, sum( i=0, sqrtint(n), sum( j=0, i, sum( k=0, j, n == i^2 + j^2 + k^2))))}; /* _Michael Somos_, Jun 05 2012 */

%o (Python) import collections; a = collections.Counter(i*i + j*j + k*k for i in range(100) for j in range(i+1) for k in range(j+1)) # _David Radcliffe_, Apr 15 2019

%Y Equivalent sequences for other numbers of squares: A000161 (2), A002635 (4), A000174 (5).

%Y Cf. A004215 (positions of zeros), A094942 (positions of ones), A124966 (positions of greater values).

%Y Cf. A005875, A016727.

%K nonn

%O 0,10

%A _N. J. A. Sloane_

%E Name clarified by _Wolfdieter Lang_, Apr 08 2013