TOPICS
Search

Square Number


SquareNumber

A square number, also called a perfect square, is a figurate number of the form S_n=n^2, where n is an integer. The square numbers for n=0, 1, ... are 0, 1, 4, 9, 16, 25, 36, 49, ... (OEIS A000290).

Binary representation of the square numbers

A plot of the first few square numbers represented as a sequence of binary bits is shown above. The top portion shows S_1 to S_(255), and the bottom shows the next 510 values.

The generating function giving the square numbers is

 (x(x+1))/((1-x)^3)=x+4x^2+9x^3+16x^4+....
(1)
SquareGnomon

The (n+1)st square number S_(n+1) is given in terms of the nth square number S_n by

 S_(n+1)=S_n+2n+1,
(2)

since

 (n+1)^2=n^2+2n+1,
(3)

which is equivalent to adding a gnomon to the previous square, as illustrated above.

SquareTriangle

The nth square number is equal to the sum of the (n-1)st and nth triangular numbers,

S_n=1/2(n-1)n+1/2n(n+1)
(4)
=n^2,
(5)

as can seen in the above diagram, in which the (n-1)st triangular number is represented by the white triangles, the nth triangular number is represented by the black triangles, and the total number of triangles is the square number S_n=n^2 (R. Sobel, pers. comm.).

Square numbers can also be generated by taking the product of two consecutive even or odd numbers and adding 1. The result obtained by carrying out this operation is then the square of the average of the initial two numbers,

 (n-1)(n+1)+1=(n^2-1)+1=n^2.
(6)

As a part of the study of Waring's problem, it is known that every positive integer is a sum of no more than 4 positive squares (g(2)=4; Lagrange's four-square theorem), that every "sufficiently large" integer is a sum of no more than 4 positive squares (G(2)=4), and that every integer is a sum of at most 3 signed squares (eg(2)=3). Actually, the basis set for representing positive integers with positive squares is {0,1,4,9,16,25,36,64,81,100,...}, so 49 need never be used. Furthermore, since an infinite number of n require four squares to represent them, the least integer G(2) such that every positive integer beyond a certain point requires G(2) squares is given by G(2)=4.

The number of representation of a number n by k squares, distinguishing signs and order, is denoted r_k(n) and called the sum of squares function. The minimum number of squares needed to represent the numbers 1, 2, 3, ... are 1, 2, 3, 1, 2, 3, 4, 2, 1, 2, ... (OEIS A002828), and the number of distinct ways to represent the numbers 1, 2, 3, ... in terms of squares are 1, 1, 1, 2, 2, 2, 2, 3, 4, 4, ... (OEIS A001156). A brute-force algorithm for enumerating the square partitions of n is repeated application of the greedy algorithm. However, this approach rapidly becomes impractical since the number of representations grows extremely rapidly with n, as shown in the following table.

nsquare partitions
104
50104
1001116
1506521
20027482

The nth nonsquare number a_n is given by

 a_n=n+|_1/2+sqrt(n)_|,
(7)

where |_x_| is the floor function, and the first few are 2, 3, 5, 6, 7, 8, 10, 11, ... (OEIS A000037).

The only numbers that are simultaneously square and pyramidal (the cannonball problem) are P_1=1 and P_(24)=4900, corresponding to S_1=1 and S_(70)=4900 (Ball and Coxeter 1987, p. 59; Ogilvy 1988; Dickson 2005, p. 25), as conjectured by Lucas (1875, 1876) and proved by Watson (1918). The cannonball problem is equivalent to solving the Diophantine equation

 y^2=1/6x(x+1)(2x+1)
(8)

(Guy 1994, p. 147).

The only numbers that are square and tetrahedral are Te_1=1, Te_2=4, and Te_(48)=19600 (giving S_1=1, S_2=4, and S_(140)=19600), as proved by Meyl (1878; cited in Dickson 2005, p. 25; Guy 1994, p. 147). In general, proving that only certain numbers are simultaneously figurate in two different ways is far from elementary.

To find the possible last digits for a square number, write n=10a+b for the number written in decimal notation as ab_(10) (a, b=0, 1, ..., 9). Then

 n^2=100a^2+20ab+b^2,
(9)

so the last digit of n^2 is the same as the last digit of b^2. The following table gives the last digit of b^2 for b=0, 1, ..., 9 (where numbers with more that one digit have only their last digit indicated, i.e., 16 becomes _6). As can be seen, the last digit can be only 0, 1, 4, 5, 6, or 9.

0123456789
0149_6_5_6_9_4_1

We can similarly examine the allowable last two digits by writing abc_(10) as

 n=100a+10b+c,
(10)

so

n^2=(100a+10b+c)^2
(11)
=100(100a^2+20ab+2ac+b^2)+(20bc+c^2),
(12)

so the last two digits must have the last two digits of 20bc+c^2. Furthermore, the last two digits can be obtained by considering only b=0, 1, 2, 3, and 4, since

 20(b+5)c+c^2=100c+(20bc+c^2)
(13)

has the same last two digits as 20bc+c^2 (with the one additional possibility that c=0 in which case the last two digits are 00). The following table (with the addition of 00) therefore exhausts all possible last two digits.

c
b123456789
0010409162536496481
1_21_44_69_96_25_56_89_24_61
2_41_84_29_76_25_76_29_84_41
3_61_24_89_56_25_96_69_44_21
4_81_64_49_36_25_16_09_04_01

The only 22 possibilities are therefore 00, 01, 04, 09, 16, 21, 24, 25, 29, 36, 41, 44, 49, 56, 61, 64, 69, 76, 81, 84, 89, and 96, which can be summarized succinctly as 00, e1, e4, 25, o6, and e9, where e stands for an even number and o for an odd number. Additionally, a necessary (but not sufficient) condition for a number to be square is that its digital root be 1, 4, 7, or 9. The digital roots of the first few squares are 1, 4, 9, 7, 7, 9, 4, 1, 9, 1, 4, 9, 7, ... (OEIS A056992), while the list of number having digital roots 1, 4, 7, or 9 is 1, 4, 7, 9, 10, 13, 16, 18, 19, 22, 25, ... (OEIS A056991).

This property of square numbers was referred to in a "puzzler" feature of a March 2008 broadcast of the NPR radio show "Car Talk." In this Puzzler, a son tells his father that his computer and math teacher assigned the class a problem to determine if a number is a perfect square. Each student is assigned a particular number, and the students are supposed to write a software program to determine the answer. The son's assigned number was 334912740121562. While the father thinks this is a hard problem, a bystander listening to the conversation states that the teacher gave the son an easy number and the bystander can give the answer immediately. The question is what does this third person know? The answer is that the number ends in the digit "2," which is not one of the possible last digits for a square number.

The following table gives the possible residues mod n for square numbers for n=1 to 20. The quantity s(n) gives the number of distinct residues for a given n.

ns(n)x^2 (mod n)
220, 1
320, 1
420, 1
530, 1, 4
640, 1, 3, 4
740, 1, 2, 4
830, 1, 4
940, 1, 4, 7
1060, 1, 4, 5, 6, 9
1160, 1, 3, 4, 5, 9
1240, 1, 4, 9
1370, 1, 3, 4, 9, 10, 12
1480, 1, 2, 4, 7, 8, 9, 11
1560, 1, 4, 6, 9, 10
1640, 1, 4, 9
1790, 1, 2, 4, 8, 9, 13, 15, 16
1880, 1, 4, 7, 9, 10, 13, 16
19100, 1, 4, 5, 6, 7, 9, 11, 16, 17
2060, 1, 4, 5, 9, 16

In general, the odd squares are congruent to 1 (mod 8) (Conway and Guy 1996). Stangl (1996) gives an explicit formula by which the number of squares s(n) in Z_n (i.e., mod n) can be calculated. Let p be an odd prime. Then s(n) is the multiplicative function given by

s(2)=2
(14)
s(p)=1/2(p+1)    (p!=2)
(15)
s(p^2)=1/2(p^2-p+2)    (p!=2)
(16)
s(2^n)={1/3(2^(n-1)+4) for n even; 1/3(2^(n-1)+5) for n odd
(17)
s(p^n)={(p^(n+1)+p+2)/(2(p+1)) for n>=3 even; (p^(n+1)+2p+1)/(2(p+1)) for n>=3 odd.
(18)

s(n) is related to the number q(n) of quadratic residues in Z_n by

 q(p^n)=s(p^n)-s(p^(n-2))
(19)

for n>=3 (Stangl 1996).

For a perfect square n, (n/p)=0 or 1 for all odd primes p<n where (n/p) is the Legendre symbol. A number n that is not a perfect square but that satisfies this relationship is called a pseudosquare.

In a Ramanujan conference talk, W. Gosper conjectured that every sum of four distinct odd squares is the sum of four distinct even squares. This conjecture was proved by M. Hirschhorn using the identity

 (4a+1)^2+(4b+1)^2+(4c+1)^2+(4d+1)^2 
=4[(a+b+c+d+1)^2+(a-b-c+d)^2+(a-b+c-d)^2+(a+b-c-d)^2],
(20)

where a, b, c, and d are positive or negative integers. Hirschhorn also showed that every sum of four distinct oddly even squares is the sum of four distinct odd squares.

A prime number p can be written as the sum of two squares iff p+1 is not divisible by 4 the (Fermat's 4n+1 theorem). An arbitrary positive number n is expressible as the sum of two squares iff, given its prime factorization

 n=p_1^(a_1)p_2^(a_2)p_3^(a_3)...p_k^(a_k),
(21)

none of p_i^(a_i)+1 is divisible by 4 (Conway and Guy 1996, p. 147). This is equivalent the requirement that all the odd factors of the squarefree part n^' of n are equal to 1 (mod 4) (Hardy and Wright 1979, Finch). The first few numbers that can be expressed as the sum of two squares are 1, 2, 4, 5, 8, 9, 10, 13, 16, 17, 18, 20, 25, 26, ... (OEIS A001481). Letting delta(n) be the fraction of numbers <=n that are expressible as the sum of two squares,

 lim_(n->infty)delta(n)=0,
(22)

and

 lim_(n->infty)delta(n)sqrt(lnn)=K,
(23)

where K is the Landau-Ramanujan constant.

Numbers expressible as the sum of three squares are those not of the form 4^k(8l+7) for k,l>=0 (Nagell 1951, p. 194; Wells 1986, pp. 48 and 56; Hardy 1999, p. 12).

The following table gives the first few numbers which require N=1, 2, 3, and 4 squares to represent them as a sum (Wells 1986, p. 70).

NSloanenumbers
1A0002901, 4, 9, 16, 25, 36, 49, 64, 81, ...
2A0004152, 5, 8, 10, 13, 17, 18, 20, 26, 29, ...
3A0004193, 6, 11, 12, 14, 19, 21, 22, 24, 27, ...
4A0042157, 15, 23, 28, 31, 39, 47, 55, 60, 63, ...

Fermat's 4n+1 theorem guarantees that every prime of the form 4n+1 is a sum of two square numbers in only one way.

There are only 31 numbers that cannot be expressed as the sum of distinct squares: 2, 3, 6, 7, 8, 11, 12, 15, 18, 19, 22, 23, 24, 27, 28, 31, 32, 33, 43, 44, 47, 48, 60, 67, 72, 76, 92, 96, 108, 112, 128 (OEIS A001422; Guy 1994; Savin 2000). The following numbers cannot be represented using fewer than five distinct squares: 55, 88, 103, 132, 172, 176, 192, 240, 268, 288, 304, 368, 384, 432, 448, 496, 512, and 752, together with all numbers obtained by multiplying these numbers by a power of 4. This gives all known such numbers less than 10^5 (Savin 2000). All numbers >188 can be expressed as the sum of at most five distinct squares, and only

 124=1+4+9+25+36+49
(24)

and

 188=1+4+9+25+49+100
(25)

require six distinct squares (Bohman et al. 1979; Guy 1994, p. 136; Savin 2000). In fact, 188 can also be represented using seven distinct squares:

 188=1+4+9+25+36+49+64.
(26)

The following table gives the numbers that can be represented in W different ways as a sum of S squares. For example,

 50=1^2+7^2=5^2+5^2
(27)

can be represented in two ways (W=2) by two squares (S=2).

SWSloanenumbers
11A0002901, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, ...
21A0252842, 5, 8, 10, 13, 17, 18, 20, 25, 26, 29, 32, ...
22A02528550, 65, 85, 125, 130, 145, 170, 185, 200, ...
31A0253213, 6, 9, 11, 12, 14, 17, 18, 19, 21, 22, 24, ...
32A02532227, 33, 38, 41, 51, 57, 59, 62, 69, 74, 75, ...
33A02532354, 66, 81, 86, 89, 99, 101, 110, 114, 126, ...
34A025324129, 134, 146, 153, 161, 171, 189, 198, ...
41A0253574, 7, 10, 12, 13, 15, 16, 18, 19, 20, 21, 22, ...
42A02535831, 34, 36, 37, 39, 43, 45, 47, 49, 50, 54, ...
43A02535928, 42, 55, 60, 66, 67, 73, 75, 78, 85, 95, 99, ...
44A02536052, 58, 63, 70, 76, 84, 87, 91, 93, 97, 98, 103, ...

The least numbers that are the sum of two squares in exactly n different ways for n=1, 2, ... are given by 2, 50, 325, 1105, 8125, 5525, 105625, 27625, 71825, 138125, 5281250, ... (OEIS A016032; Beiler 1966, pp. 140-141; Rubin 1977-78; Culberson 1978-79; Hardy and Wright 1979; Rivera).

The product of four distinct nonzero integers in arithmetic progression is square only for (-3, -1, 1, 3), giving (-3)(-1)(1)(3)=9 (Le Lionnais 1983, p. 53). It is possible to have three squares in arithmetic progression, but not four (Dickson 2005, pp. 435-440). If these numbers are r^2, s^2, and t^2, there are positive integers p and q such that

r=|p^2-2pq-q^2|
(28)
s=p^2+q^2
(29)
t=p^2+2pq-q^2,
(30)

where (p,q)=1 and one of r, s, or t is even (Dickson 2005, pp. 437-438). Every three-term progression of squares can be associated with a Pythagorean triple (X,Y,Z) by

X=1/2(r+t)
(31)
Y=1/2(t-r)
(32)
Z=s
(33)

(Robertson 1996).

Catalan's conjecture states that 8 and 9 (2^3 and 3^2) are the only consecutive powers (excluding 0 and 1), i.e., the only solution to Catalan's Diophantine problem. This conjecture has not yet been proved or refuted, although R. Tijdeman has proved that there can be only a finite number of exceptions should the conjecture not hold. It is also known that 8 and 9 are the only consecutive cubic and square numbers (in either order).

The numbers that are not the difference of two squares are 2, 6, 10, 14, 18, ... (OEIS A016825; Wells 1986, p. 76).

A square number can be the concatenation of two squares, as in the case 16=4^2 and 9=3^2 giving 169=13^2. The first few numbers that are neither square nor the sum of a square and a prime are 10, 34, 58, 85, 91, 130, 214, ... (OEIS A020495).

It is conjectured that, other than 10^(2n), 4×10^(2n) and 9×10^(2n), there are only a finite number of squares n^2 having exactly two distinct nonzero digits (Guy 1994, p. 262). The first few such n are 4, 5, 6, 7, 8, 9, 11, 12, 15, 21, ... (OEIS A016070), corresponding to n^2 of 16, 25, 36, 49, 64, 81, 121, ... (OEIS A018884).

The following table gives the first few numbers which, when squared, give numbers composed of only certain digits. The values of n such that n^2 contains exactly two different digits are given by 4, 5, 6, 7, 8, 9, 10, 11, 12, 15, 20, ... (OEIS A016069), whose squares are 16, 25 36, 49, 64, ... (OEIS A018885).

digitsSloanen, n^2
1, 2, 3A0301751, 11, 111, 36361, 363639, ...
A0301741, 121, 12321, 1322122321, ...
1, 4, 6A0276771, 2, 4, 8, 12, 21, 38, 108, ...
A0276761, 4, 16, 64, 144, 441, 1444, ...
1, 4, 9A0276751, 2, 3, 7, 12, 21, 38, 107, ...
A0067161, 4, 9, 49, 144, 441, 1444, 11449, ...
2, 4, 8A0276792, 22, 168, 478, 2878, 210912978, ...
A0276784, 484, 28224, 228484, 8282884, ...
4, 5, 6A0301772, 8, 216, 238, 258, 738, 6742, ...
A0301764, 64, 46656, 56644, 66564, ...

For three digits, an extreme example containing only the digits 7, 8, and 9 is

 9949370777987917^2 
 =98989978877879888789778997998889
(34)

No squares are known containing only the digits 013 or 678. Unique solutions are known for 019, 039, 056, 079, 568, and 789. The longest known is

 81401637345465395512991484^2 
 =6626226562522666562566262626266252566552622656522256,
(35)

with 52 digits. A list of known solutions to the 3-digit square problem is maintained by Mishima.

Brown numbers are pairs (m,n) of integers satisfying the condition of Brocard's problem, i.e., such that

 n!+1=m^2,
(36)

where n! is a factorial. Only three such numbers are known: (5,4), (11,5), (71,7). Erdős conjectured that these are the only three such pairs.

Either 5x^2+4=y^2 or 5x^2-4=y^2 has a solution in positive integers iff, for some n, (x,y)=(F_n,L_n), where F_n is a Fibonacci number and L_n is a Lucas number (Honsberger 1985, pp. 114-118).

The smallest and largest square numbers containing the digits 1 to 9 are

 11826^2=139854276
(37)
 30384^2=923187456.
(38)

The smallest and largest square numbers containing the digits 0 to 9 are

 32043^2=1026753849,
(39)
 99066^2=9814072356
(40)

(Madachy 1979, p. 159). The smallest and largest square numbers containing the digits 1 to 9 twice each are

 335180136^2=112345723568978496
(41)
 999390432^2=998781235573146624,
(42)

and the smallest and largest containing 1 to 9 three times are

 10546200195312^2=111222338559598866946777344
(43)
 31621017808182^2=999888767225363175346145124
(44)

(Madachy 1979, p. 159).

Madachy (1979, p. 165) also considers numbers that are equal to the sum of the squares of their two "halves" such as

1233=12^2+33^2
(45)
8833=88^2+33^2
(46)
10100=10^2+100^2
(47)
5882353=588^2+2353^2,
(48)

in addition to a number of others.


See also

Antisquare Number, Biquadratic Number, Brocard's Problem, Brown Numbers, Cannonball Problem, Catalan's Conjecture, Centered Square Number, Clark's Triangle, Cubic Number, Diophantine Equation, Fermat's 4n+1 Theorem, Greedy Algorithm, Gross, Heptagonal Square Number, Lagrange's Four-Square Theorem, Landau-Ramanujan Constant, Octagonal Square Number, Partition, Pentagonal Square Number, Pseudosquare, Pyramidal Number, Squarefree, Square Triangular Number, Sum of Squares Function, Waring's Problem Explore this topic in the MathWorld classroom

Portions of this entry contributed by Len Goodman

Explore with Wolfram|Alpha

References

Archibald, R. G. "Waring's Problem: Squares." Scripta Math. 7, 33-48, 1940.Ball, W. W. R. and Coxeter, H. S. M. Mathematical Recreations and Essays, 13th ed. New York: Dover, p. 59, 1987.Beiler, A. H. Recreations in the Theory of Numbers: The Queen of Mathematics Entertains. New York: Dover, 1966.Bohman, J.; Fröberg, C.-E.; and Riesel, H. "Partitions in Squares." BIT 19, 297-301, 1979.Cole, C. "rec.puzzles FAQ3." http://www.ifindkarma.com/attic/PUZZLES/rec.puz.faq3.Conway, J. H. and Guy, R. K. The Book of Numbers. New York: Springer-Verlag, pp. 30-32 and 146-147, 1996.Culberson, J. "Solution to Problem 590." J. Recr. Math. 11, 137-138, 1978-79.Dickson, L. E. History of the Theory of Numbers, Vol. 2: Diophantine Analysis. New York: Dover, 2005.Finch, S. "On a Generalized Fermat-Wiles Equation." http://algo.inria.fr/csolve/fermat.pdf.Grosswald, E. Representations of Integers as Sums of Squares. New York: Springer-Verlag, 1985.Guy, R. K. "Sums of Squares" and "Squares with Just Two Different Decimal Digits." §C20 and F24 in Unsolved Problems in Number Theory, 2nd ed. New York: Springer-Verlag, pp. 136-138, 147, and 262, 1994.Hajdu, L. and Pintér, Á. "Square Product of Three Integers in Short Intervals." Math. Comput. 68, 1299-1301, 1999.Hardy, G. H. Ramanujan: Twelve Lectures on Subjects Suggested by His Life and Work, 3rd ed. New York: Chelsea, 1999.Hardy, G. H. and Wright, E. M. "The Representation of a Number by Two or Four Squares." Ch. 20 in An Introduction to the Theory of Numbers, 5th ed. Oxford, England: Clarendon Press, pp. 297-316, 1979.Honsberger, R. "A Second Look at the Fibonacci and Lucas Numbers." Ch. 8 in Mathematical Gems III. Washington, DC: Math. Assoc. Amer., 1985.Landau, E. "Über die Einteilung der positiven ganzen Zahlen in vier Klassen nach der Mindeszahl der zu ihrer additiven Zusammensetzung erforderlichen Quadrate." Arch. Math. Phys. 13, 305-312, 1908.Le Lionnais, F. Les nombres remarquables. Paris: Hermann, 1983.Lucas, É. Question 1180. Nouv. Ann. Math. Ser. 2 14, 336, 1875.Lucas, É. Solution de Question 1180. Nouv. Ann. Math. Ser. 2 15, 429-432, 1876.Madachy, J. S. Madachy's Mathematical Recreations. New York: Dover, pp. 159 and 165, 1979.Meyl, A.-J.-J. Solution de Question 1194. Nouv. Ann. Math. 17, 464-467, 1878.Mishima, H. "Sporadic Solutions." http://www.asahi-net.or.jp/~KC2H-MSM/mathland/math02/math0210.htm.Nagell, T. Introduction to Number Theory. New York: Wiley, 1951.Ogilvy, C. S. and Anderson, J. T. Excursions in Number Theory. New York: Dover, pp. 77 and 152, 1988.Pappas, T. "Triangular, Square & Pentagonal Numbers." The Joy of Mathematics. San Carlos, CA: Wide World Publ./Tetra, p. 214, 1989.Pietenpol, J. L. "Square Triangular Numbers." Amer. Math. Monthly 69, 168-169, 1962.Rivera, C. "Problems & Puzzles: Puzzle 062-The qs-Sequence." http://www.primepuzzles.net/puzzles/puzz_062.htm.Robertson, J. P. "Magic Squares of Squares." Math. Mag. 69, 289-293, 1996.Rubin, F. "Problem 590." J. Recr. Math. 10, 46, 1977-78.Savin, A. "Shape Numbers." Quantum 11, 14-18, 2000.Sloane, N. J. A. Sequences A000037/M0613, A000290/M3356, A000415, A000419, A001156/M0221, A001422, A001481/M0968, A002828/M0404, A004215/M4349, A006716/M3369, A016069, A016070, A016032, A016825, A018884, A018885, A020495, A025284, A025285, A025321, A025322, A025323, A025324, A025357, A025358, A025359, A025360, A027675, A027676, A027677, A027678, A027679, A030174, A030175, A030176, A030177, A056991, and A056992 in "The On-Line Encyclopedia of Integer Sequences."Stangl, W. D. "Counting Squares in Z_n." Math. Mag. 69, 285-289, 1996.Taussky-Todd, O. "Sums of Squares." Amer. Math. Monthly 77, 805-830, 1970.Vardi, I. Computational Recreations in Mathematica. Reading, MA: Addison-Wesley, pp. 20 and 234-237, 1991.Watson, G. N. "The Problem of the Square Pyramid." Messenger. Math. 48, 1-22, 1918.Wells, D. The Penguin Dictionary of Curious and Interesting Numbers. Middlesex, England: Penguin Books, pp. 48 and 70, 1986.

Referenced on Wolfram|Alpha

Square Number

Cite this as:

Goodman, Len and Weisstein, Eric W. "Square Number." From MathWorld--A Wolfram Web Resource. https://mathworld.wolfram.com/SquareNumber.html

Subject classifications