|
| |
|
|
A002828
|
|
Least number of squares that add up to n.
(Formerly M0404 N0155)
|
|
28
| |
|
|
0, 1, 2, 3, 1, 2, 3, 4, 2, 1, 2, 3, 3, 2, 3, 4, 1, 2, 2, 3, 2, 3, 3, 4, 3, 1, 2, 3, 4, 2, 3, 4, 2, 3, 2, 3, 1, 2, 3, 4, 2, 2, 3, 3, 3, 2, 3, 4, 3, 1, 2, 3, 2, 2, 3, 4, 3, 3, 2, 3, 4, 2, 3, 4, 1, 2, 3, 3, 2, 3, 3, 4, 2, 2, 2, 3, 3, 3, 3, 4, 2, 1, 2, 3, 3, 2, 3, 4, 3, 2, 2, 3, 4, 3, 3, 4, 3, 2, 2, 3, 1, 2, 3, 4, 2, 3
(list; graph; refs; listen; history; internal format)
|
|
|
|
OFFSET
| 0,3
|
|
|
COMMENTS
| Lagrange's "Four Squares theorem" states that a(n) <= 4.
It is easy to show that this is also the least number of squares that add up to n^3.
|
|
|
REFERENCES
| N. J. A. Sloane, A Handbook of Integer Sequences, Academic Press, 1973 (includes this sequence).
N. J. A. Sloane and Simon Plouffe, The Encyclopedia of Integer Sequences, Academic Press, 1995 (includes this sequence).
|
|
|
LINKS
| T. D. Noe, Table of n, a(n) for n=1..1000
N. J. A. Sloane, Transforms
Eric Weisstein's World of Mathematics, Square Number
|
|
|
MAPLE
| with(transforms);
sq:=[seq(n^2, n=1..20)];
LAGRANGE(sq, 4, 120);
|
|
|
MATHEMATICA
| SquareCnt[n_] := If[SquaresR[1, n] > 0, 1, If[SquaresR[2, n] > 0, 2, If[SquaresR[3, n] > 0, 3, 4]]]; Table[SquareCnt[n], {n, 150}] (* T. D. Noe, Apr 01 2011 *)
|
|
|
PROG
| (PARI) istwo(n:int)=my(f); if(n<3, return(n>=0); ); f=factor(oddres(n)); for(i=1, #f[, 1], if(bitand(f[i, 2], 1)==1&&bitand(f[i, 1], 3)==3, return(0))); 1
isthree(n:int)=my(tmp=valuation(n, 2)); bitand(tmp, 1)||bitand(n>>tmp, 7)!=7
a(n)=if(issquare(n), !!n, if(istwo(n), 2, 4-isthree(n))) \\ Charles R Greathouse IV, Jul 19 2011
|
|
|
CROSSREFS
| Cf. A000290, A000415, A000419, A004215, A000378, A001481.
Sequence in context: A194063 A194053 A194050 * A191091 A098066 A096436
Adjacent sequences: A002825 A002826 A002827 * A002829 A002830 A002831
|
|
|
KEYWORD
| nonn,nice
|
|
|
AUTHOR
| N. J. A. Sloane (njas(AT)research.att.com).
|
|
|
EXTENSIONS
| More terms from Arlin Anderson (starship1(AT)gmail.com)
|
| |
|
|