A square number, also called a perfect square, is a figurate number of
the form ,
where
is an integer. The square numbers for
, 1, ... are 0, 1, 4, 9, 16, 25, 36, 49, ... (OEIS A000290).
A plot of the first few square numbers represented as a sequence of binary bits
is shown above. The top portion shows to
, and the bottom shows the next 510 values.
The generating function giving the square numbers is
|
(1)
|
The st square number
is given in terms of the
th square number
by
|
(2)
|
which is equivalent to adding a gnomon to the previous square, as illustrated above.
The th
square number is equal to the sum of the
st and
th triangular numbers,
|
(3)
| |||
|
(4)
|
as can be seen in the above diagram, in which the st triangular number
is represented by the white triangles, the
th triangular number is
represented by the black triangles, and the total number of triangles is the square
number
(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,
|
(5)
|
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 (; Lagrange's
four-square theorem), that every "sufficiently large" integer
is a sum of no more than 4 positive squares (
), and that every integer
is a sum of at most 3 signed squares (
). Actually, the basis set for representing positive
integers with positive squares is
, so 49 need never be used.
Furthermore, since an infinite number of
require four squares to represent them, the least integer
such that every positive
integer beyond a certain point can be represented by at most
squares is given by
.
The number of representations of a number by
squares, distinguishing signs and order, is denoted
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 numbers of unordered partitions of the numbers
1, 2, 3, ... into positive squares are 1, 1, 1, 2, 2, 2, 2, 3, 4, 4, ... (OEIS A001156). A brute-force algorithm
for enumerating the square partitions of
uses backtracking through
nonincreasing positive square parts. However, this approach rapidly becomes impractical
since the number of representations grows extremely rapidly with
, as shown in the following table.
| square partitions | |
| 10 | 4 |
| 50 | 104 |
| 100 | 1116 |
| 150 | 6521 |
| 200 | 27482 |
For a positive integer , the
th nonsquare number
is given by
|
(6)
|
where
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 positive square and square pyramidal (the cannonball problem) are
and
, corresponding to
and
(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
|
(7)
|
(Guy 1994, p. 147).
The only positive numbers that are square and tetrahedral are ,
, and
(giving
,
, and
), as proved by Meyl (1878; cited in Guy 1994,
p. 147; Dickson 2005, p. 25). 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 , where
is a nonnegative integer
and
,
1, ..., 9. Then
|
(8)
|
so the last digit of is the same as the last digit
of
. The following table gives the last
digit of
for
, 1, ..., 9 (where numbers with more than 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.
| 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
| 0 | 1 | 4 | 9 | _6 | _5 | _6 | _9 | _4 | _1 |
We can similarly examine the allowable last two digits by writing
as
|
(9)
|
so
|
(10)
| |||
|
(11)
|
so the last two digits must have the last two digits of . Furthermore, the last two digits can be obtained by considering only
, 1, 2, 3, and 4, since
|
(12)
|
has the same last two digits as (with the one additional possibility that
in which case the last two digits
are 00). The following table (with the addition of 00) therefore exhausts all possible
last two digits.
| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | |
| 0 | 01 | 04 | 09 | 16 | 25 | 36 | 49 | 64 | 81 |
| 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, ,
, 25,
, and
, where
stands for an even number and
for an odd
number. Additionally, a necessary (but not sufficient)
condition for a positive number to be square is that its digital
root be 1, 4, 7, or 9. The digital roots of the
first few positive squares are 1, 4, 9, 7, 7, 9, 4, 1, 9, 1, 4, 9, 7, ... (OEIS A056992), while the list of numbers 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 . 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 for square numbers for
to 20. The quantity
gives the number of distinct residues
for a given
.
| 2 | 2 | 0, 1 |
| 3 | 2 | 0, 1 |
| 4 | 2 | 0, 1 |
| 5 | 3 | 0, 1, 4 |
| 6 | 4 | 0, 1, 3, 4 |
| 7 | 4 | 0, 1, 2, 4 |
| 8 | 3 | 0, 1, 4 |
| 9 | 4 | 0, 1, 4, 7 |
| 10 | 6 | 0, 1, 4, 5, 6, 9 |
| 11 | 6 | 0, 1, 3, 4, 5, 9 |
| 12 | 4 | 0, 1, 4, 9 |
| 13 | 7 | 0, 1, 3, 4, 9, 10, 12 |
| 14 | 8 | 0, 1, 2, 4, 7, 8, 9, 11 |
| 15 | 6 | 0, 1, 4, 6, 9, 10 |
| 16 | 4 | 0, 1, 4, 9 |
| 17 | 9 | 0, 1, 2, 4, 8, 9, 13, 15, 16 |
| 18 | 8 | 0, 1, 4, 7, 9, 10, 13, 16 |
| 19 | 10 | 0, 1, 4, 5, 6, 7, 9, 11, 16, 17 |
| 20 | 6 | 0, 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 in
(i.e., mod
) can be calculated. Let
be an odd prime.
Then
is the multiplicative function given on
prime powers by the following formulas, where the exponent
is a positive
integer:
|
(13)
| |||
|
(14)
| |||
|
(15)
| |||
|
(16)
| |||
|
(17)
|
is related to the number
of unit quadratic residues
in
by
|
(18)
|
for
(Stangl 1996).
For a perfect square ,
or 1 for all odd primes
where
is the Legendre symbol.
For a fixed odd prime
, the pseudosquare
is the least nonsquare positive
integer congruent to 1 (mod 8) for which
for every odd
prime
.
Hirschhorn (2001) proved Gosper's conjecture that every sum of four distinct odd squares is the sum of four distinct even squares using the identity
|
(19)
|
where ,
,
, and
are integers. Hirschhorn (2001)
also showed that a sum
of four distinct even squares is a sum of four distinct
odd squares when
.
A prime number can be written as the sum of two squares iff
is not divisible by 4 (Fermat's
4n+1 theorem). An arbitrary positive integer
is expressible as the sum of two squares
iff, given its prime factorization
|
(20)
|
none of
is divisible by 4 (Conway and Guy 1996, p. 147). This is equivalent to the requirement
that all the odd prime factors of the squarefree part
of
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
be the fraction of numbers
that are expressible as the sum of two squares,
|
(21)
|
and
|
(22)
|
where
is the Landau-Ramanujan constant.
Numbers expressible as the sum of three squares are those not of the form
for
(Nagell 1951, p. 194; Wells 1986, pp. 48 and 56; Hardy 1999, p. 12).
The following table gives the first few numbers which require , 2, 3, and 4 squares to represent them as a sum (Wells 1986,
p. 70).
| Sloane | numbers | |
| 1 | A000290 | 1, 4, 9, 16, 25, 36, 49, 64, 81, ... |
| 2 | A000415 | 2, 5, 8, 10, 13, 17, 18, 20, 26, 29, ... |
| 3 | A000419 | 3, 6, 11, 12, 14, 19, 21, 22, 24, 27, ... |
| 4 | A004215 | 7, 15, 23, 28, 31, 39, 47, 55, 60, 63, ... |
Fermat's 4n+1 theorem guarantees that every prime of the
form
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 require exactly five distinct positive
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 (Savin 2000). All numbers
can be expressed as the sum of at most five distinct
squares, and only
|
(23)
|
and
|
(24)
|
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:
|
(25)
|
The following table gives the numbers with exactly unordered representations as a sum of
positive squares, with repetition allowed and signs ignored.
For example,
|
(26)
|
can be represented in two ways () by two squares (
).
| Sloane | numbers | ||
| 1 | 1 | A000290 | 1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, ... |
| 2 | 1 | A025284 | 2, 5, 8, 10, 13, 17, 18, 20, 25, 26, 29, 32, ... |
| 2 | 2 | A025285 | 50, 65, 85, 125, 130, 145, 170, 185, 200, ... |
| 3 | 1 | A025321 | 3, 6, 9, 11, 12, 14, 17, 18, 19, 21, 22, 24, ... |
| 3 | 2 | A025322 | 27, 33, 38, 41, 51, 57, 59, 62, 69, 74, 75, ... |
| 3 | 3 | A025323 | 54, 66, 81, 86, 89, 99, 101, 110, 114, 126, ... |
| 3 | 4 | A025324 | 129, 134, 146, 153, 161, 171, 189, 198, ... |
| 4 | 1 | A025357 | 4, 7, 10, 12, 13, 15, 16, 18, 19, 20, 21, 22, ... |
| 4 | 2 | A025358 | 31, 34, 36, 37, 39, 43, 45, 47, 49, 50, 54, ... |
| 4 | 3 | A025359 | 28, 42, 55, 60, 66, 67, 73, 75, 78, 79, 85, 92, 95, 99, ... |
| 4 | 4 | A025360 | 52, 58, 63, 70, 76, 84, 87, 91, 93, 97, 98, 105, ... |
The least numbers that are the sum of two positive squares in exactly unordered ways for
, 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).
Four distinct nonzero integers in arithmetic progression can have a square
product. For example, (,
, 1, 3) gives
(Le Lionnais 1983, p. 53). It is possible
to have three squares in nonconstant arithmetic
progression, but not four (Dickson 2005, pp. 435-440). A family of three-term
progressions
,
, and
is given by
|
(27)
| |||
|
(28)
| |||
|
(29)
|
where
are coprime integers
(Dickson 2005, pp. 437-438). Multiplying
,
,
and
by a common positive integer gives further examples.
Every nonconstant three-term progression of positive squares, ordered with
, can be associated with a Pythagorean
triple
by
|
(30)
| |||
|
(31)
| |||
|
(32)
|
(Robertson 1996).
Catalan's conjecture, proved by Preda Mihăilescu (2004), states that 8 and 9 ( and
) are the only consecutive powers
of positive integers greater than 1 with exponents
greater than 1, i.e., the only solution to Catalan's
Diophantine problem. It is also known that 8 and 9 are the only consecutive cubic and square numbers greater than 1 (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 and
giving
. 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 ,
and
, there are only a finite
number of squares
having exactly two distinct decimal digits (Guy 1994, p. 262).
The first few such
are 4, 5, 6, 7, 8, 9, 11, 12, 15, 21, ... (OEIS A016070),
corresponding to
of 16, 25, 36, 49, 64, 81, 121, .... These squares occur in OEIS A018884
after its first three terms 1, 4, and 9. That sequence allows at most two distinct
digits and excludes squares ending in 0.
The following table gives the first few numbers which, when squared, give numbers composed of only certain digits. The values of such that
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, .... The sequence OEIS A018885
allows at most two distinct digits, so it also includes
the one-digit squares 0, 1, 4, and 9. In the row for the digits 2, 4, and 8 below,
OEIS A027679 requires all three digits
to occur and begins with the third displayed root, 168.
| digits | Sloane | |
| 1, 2, 3 | A030175 | 1, 11, 111, 36361, 363639, ... |
| A030174 | 1, 121, 12321, 1322122321, ... | |
| 1, 4, 6 | A027677 | 1, 2, 4, 8, 12, 21, 38, 108, ... |
| A027676 | 1, 4, 16, 64, 144, 441, 1444, ... | |
| 1, 4, 9 | A027675 | 1, 2, 3, 7, 12, 21, 38, 107, ... |
| A006716 | 1, 4, 9, 49, 144, 441, 1444, 11449, ... | |
| 2, 4, 8 | A027679 | 2, 22, 168, 478, 2878, 210912978, ... |
| A027678 | 4, 484, 28224, 228484, 8282884, ... | |
| 4, 5, 6 | A030177 | 2, 8, 216, 238, 258, 738, 6742, ... |
| A030176 | 4, 64, 46656, 56644, 66564, ... |
For three digits, an extreme example containing only the digits 7, 8, and 9 is
|
(33)
|
Mishima's list of sporadic solutions, last updated in 2008, gives no square containing exactly the three digits 0, 1, and 3 or 6, 7, and 8, and gives one listed solution for each of the digit sets 019, 039, 056, 079, 568, and 789. These search results do not establish uniqueness among all squares. A listed 52-digit example is
|
(34)
|
(Mishima 2008).
Brown numbers are pairs of positive integers
satisfying the condition of Brocard's problem,
i.e., such that
|
(35)
|
where
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
or
has a solution in positive integers iff,
for some
,
, where
is a Fibonacci number
and
is a Lucas number (Honsberger 1985, pp. 114-118).
The smallest and largest square numbers containing each of the digits 1 to 9 exactly once are
|
(36)
|
|
(37)
|
The smallest and largest square numbers containing each of the digits 0 to 9 exactly once are
|
(38)
|
|
(39)
|
(Madachy 1979, p. 159). The smallest and largest square numbers containing the digits 1 to 9 twice each are
|
(40)
|
|
(41)
|
and the smallest and largest containing 1 to 9 three times are
|
(42)
|
|
(43)
|
(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
|
(44)
| |||
|
(45)
| |||
|
(46)
| |||
|
(47)
|
in addition to a number of others.