Sum of squares function
In-game article clicks load inline without leaving the challenge.
In number theory, the sum of squares function is an arithmetic function that gives the number of representations for a given positive integer n {\displaystyle n} as the sum of k {\displaystyle k} squares, where representations that differ only in the order of the summands or in the signs of the numbers being squared are counted as different. It is denoted by r k ( n ) {\displaystyle r_{k}(n)}.
Definition
The function is defined as
r k ( n ) = | { ( a 1 , a 2 , … , a k ) ∈ Z k : n = a 1 2 + a 2 2 + ⋯ + a k 2 } | {\displaystyle r_{k}(n)=|\{(a_{1},a_{2},\ldots ,a_{k})\in \mathbb {Z} ^{k}\:\ n=a_{1}^{2}+a_{2}^{2}+\cdots +a_{k}^{2}\}|}
where | | {\displaystyle |\,\ |} denotes the cardinality of a set. In other words, r k ( n ) {\displaystyle r_{k}(n)} is the number of ways n {\displaystyle n} can be written as a sum of k {\displaystyle k} squares.
For example, r 2 ( 1 ) = 4 {\displaystyle r_{2}(1)=4} since 1 = 0 2 + ( ± 1 ) 2 = ( ± 1 ) 2 + 0 2 {\displaystyle 1=0^{2}+(\pm 1)^{2}=(\pm 1)^{2}+0^{2}} where each sum has two sign combinations, and also r 2 ( 2 ) = 4 {\displaystyle r_{2}(2)=4} since 2 = ( ± 1 ) 2 + ( ± 1 ) 2 {\displaystyle 2=(\pm 1)^{2}+(\pm 1)^{2}} with four sign combinations. On the other hand, r 2 ( 3 ) = 0 {\displaystyle r_{2}(3)=0} because there is no way to represent 3 as a sum of two squares.
Formulae
k = 2

The number of ways to write a natural number as sum of two squares is given by r 2 ( n ) {\displaystyle r_{2}(n)}. It is given explicitly by
r 2 ( n ) = 4 ( d 1 ( n ) − d 3 ( n ) ) {\displaystyle r_{2}(n)=4(d_{1}(n)-d_{3}(n))}
where d 1 ( n ) {\displaystyle d_{1}(n)} is the number of divisors of n {\displaystyle n} which are congruent to 1 modulo 4 and d 3 ( n ) {\displaystyle d_{3}(n)} is the number of divisors of n {\displaystyle n} which are congruent to 3 modulo 4. Using sums, the expression can be written as:
r 2 ( n ) = 4 ∑ d ∣ n d ≡ 1 , 3 ( mod 4 ) ( − 1 ) ( d − 1 ) / 2 {\displaystyle r_{2}(n)=4\sum _{d\mid n \atop d\,\equiv \,1,3{\pmod {4}}}(-1)^{(d-1)/2}}
The prime factorization n = 2 g p 1 f 1 p 2 f 2 ⋯ q 1 h 1 q 2 h 2 ⋯ {\displaystyle n=2^{g}p_{1}^{f_{1}}p_{2}^{f_{2}}\cdots q_{1}^{h_{1}}q_{2}^{h_{2}}\cdots }, where p i {\displaystyle p_{i}} are the prime factors of the form p i ≡ 1 ( mod 4 ) , {\displaystyle p_{i}\equiv 1{\pmod {4}},} and q i {\displaystyle q_{i}} are the prime factors of the form q i ≡ 3 ( mod 4 ) {\displaystyle q_{i}\equiv 3{\pmod {4}}} gives another formula
r 2 ( n ) = 4 ( f 1 + 1 ) ( f 2 + 1 ) ⋯ {\displaystyle r_{2}(n)=4(f_{1}+1)(f_{2}+1)\cdots }, if all exponents h 1 , h 2 , ⋯ {\displaystyle h_{1},h_{2},\cdots } are even. If one or more h i {\displaystyle h_{i}} are odd, then r 2 ( n ) = 0 {\displaystyle r_{2}(n)=0}.
k = 3
Gauss proved that for a squarefree number n > 4 {\displaystyle n>4},
r 3 ( n ) = { 24 h ( − n ) , if n ≡ 3 ( mod 8 ) , 0 if n ≡ 7 ( mod 8 ) , 12 h ( − 4 n ) otherwise , {\displaystyle r_{3}(n)={\begin{cases}24h(-n),&{\text{if }}n\equiv 3{\pmod {8}},\\0&{\text{if }}n\equiv 7{\pmod {8}},\\12h(-4n)&{\text{otherwise}},\end{cases}}}
where h ( m ) {\displaystyle h(m)} denotes the class number of an integer m {\displaystyle m}.
There exist extensions of Gauss' formula to arbitrary integer n {\displaystyle n}.
k = 4
The number of ways to represent n {\displaystyle n} as the sum of four squares was due to Carl Gustav Jakob Jacobi and it is eight times the sum of all its divisors which are not divisible by 4, i.e.
r 4 ( n ) = 8 ∑ d ∣ n , 4 ∤ d d . {\displaystyle r_{4}(n)=8\sum _{d\,\mid \,n,\ 4\,\nmid \,d}d.}
Representing n = 2 k m {\displaystyle n=2^{k}m}, where m {\displaystyle m} is an odd integer, one can express r 4 ( n ) {\displaystyle r_{4}(n)} in terms of the divisor function as follows:
r 4 ( n ) = 8 σ ( 2 min { k , 1 } m ) . {\displaystyle r_{4}(n)=8\sigma (2^{\min\{k,1\}}m).}
k = 6
The number of ways to represent n {\displaystyle n} as the sum of six squares is given by
r 6 ( n ) = 4 ∑ d ∣ n d 2 ( 4 ( − 4 n / d ) − ( − 4 d ) ) , {\displaystyle r_{6}(n)=4\sum _{d\mid n}d^{2}{\big (}4\left({\tfrac {-4}{n/d}}\right)-\left({\tfrac {-4}{d}}\right){\big )},}
where ( ⋅ ⋅ ) {\displaystyle \left({\tfrac {\cdot }{\cdot }}\right)} is the Kronecker symbol.
k = 8
Jacobi also found an explicit formula for the case k = 8 {\displaystyle k=8}:
r 8 ( n ) = 16 ∑ d ∣ n ( − 1 ) n + d d 3 . {\displaystyle r_{8}(n)=16\sum _{d\,\mid \,n}(-1)^{n+d}d^{3}.}
Generating function
The generating function of the sequence r k ( n ) {\displaystyle r_{k}(n)} for fixed k can be expressed in terms of the Jacobi theta function:
ϑ ( 0 ; q ) k = ϑ 3 k ( q ) = ∑ n = 0 ∞ r k ( n ) q n , {\displaystyle \vartheta (0;q)^{k}=\vartheta _{3}^{k}(q)=\sum _{n=0}^{\infty }r_{k}(n)q^{n},}
where
ϑ ( 0 ; q ) = ∑ n = − ∞ ∞ q n 2 = 1 + 2 q + 2 q 4 + 2 q 9 + 2 q 16 + ⋯ . {\displaystyle \vartheta (0;q)=\sum _{n=-\infty }^{\infty }q^{n^{2}}=1+2q+2q^{4}+2q^{9}+2q^{16}+\cdots .}
Numerical values
The first 30 values for r k ( n ) , k = 1 , … , 8 {\displaystyle r_{k}(n),\;k=1,\dots ,8} are listed in the table below:
| n | = | r 1 ( n ) {\displaystyle r_{1}(n)} | r 2 ( n ) {\displaystyle r_{2}(n)} | r 3 ( n ) {\displaystyle r_{3}(n)} | r 4 ( n ) {\displaystyle r_{4}(n)} | r 5 ( n ) {\displaystyle r_{5}(n)} | r 6 ( n ) {\displaystyle r_{6}(n)} | r 7 ( n ) {\displaystyle r_{7}(n)} | r 8 ( n ) {\displaystyle r_{8}(n)} |
|---|---|---|---|---|---|---|---|---|---|
| 0 | 0 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 |
| 1 | 1 | 2 | 4 | 6 | 8 | 10 | 12 | 14 | 16 |
| 2 | 2 | 0 | 4 | 12 | 24 | 40 | 60 | 84 | 112 |
| 3 | 3 | 0 | 0 | 8 | 32 | 80 | 160 | 280 | 448 |
| 4 | 22 | 2 | 4 | 6 | 24 | 90 | 252 | 574 | 1136 |
| 5 | 5 | 0 | 8 | 24 | 48 | 112 | 312 | 840 | 2016 |
| 6 | 2×3 | 0 | 0 | 24 | 96 | 240 | 544 | 1288 | 3136 |
| 7 | 7 | 0 | 0 | 0 | 64 | 320 | 960 | 2368 | 5504 |
| 8 | 23 | 0 | 4 | 12 | 24 | 200 | 1020 | 3444 | 9328 |
| 9 | 32 | 2 | 4 | 30 | 104 | 250 | 876 | 3542 | 12112 |
| 10 | 2×5 | 0 | 8 | 24 | 144 | 560 | 1560 | 4424 | 14112 |
| 11 | 11 | 0 | 0 | 24 | 96 | 560 | 2400 | 7560 | 21312 |
| 12 | 22×3 | 0 | 0 | 8 | 96 | 400 | 2080 | 9240 | 31808 |
| 13 | 13 | 0 | 8 | 24 | 112 | 560 | 2040 | 8456 | 35168 |
| 14 | 2×7 | 0 | 0 | 48 | 192 | 800 | 3264 | 11088 | 38528 |
| 15 | 3×5 | 0 | 0 | 0 | 192 | 960 | 4160 | 16576 | 56448 |
| 16 | 24 | 2 | 4 | 6 | 24 | 730 | 4092 | 18494 | 74864 |
| 17 | 17 | 0 | 8 | 48 | 144 | 480 | 3480 | 17808 | 78624 |
| 18 | 2×32 | 0 | 4 | 36 | 312 | 1240 | 4380 | 19740 | 84784 |
| 19 | 19 | 0 | 0 | 24 | 160 | 1520 | 7200 | 27720 | 109760 |
| 20 | 22×5 | 0 | 8 | 24 | 144 | 752 | 6552 | 34440 | 143136 |
| 21 | 3×7 | 0 | 0 | 48 | 256 | 1120 | 4608 | 29456 | 154112 |
| 22 | 2×11 | 0 | 0 | 24 | 288 | 1840 | 8160 | 31304 | 149184 |
| 23 | 23 | 0 | 0 | 0 | 192 | 1600 | 10560 | 49728 | 194688 |
| 24 | 23×3 | 0 | 0 | 24 | 96 | 1200 | 8224 | 52808 | 261184 |
| 25 | 52 | 2 | 12 | 30 | 248 | 1210 | 7812 | 43414 | 252016 |
| 26 | 2×13 | 0 | 8 | 72 | 336 | 2000 | 10200 | 52248 | 246176 |
| 27 | 33 | 0 | 0 | 32 | 320 | 2240 | 13120 | 68320 | 327040 |
| 28 | 22×7 | 0 | 0 | 0 | 192 | 1600 | 12480 | 74048 | 390784 |
| 29 | 29 | 0 | 8 | 72 | 240 | 1680 | 10104 | 68376 | 390240 |
| 30 | 2×3×5 | 0 | 0 | 48 | 576 | 2720 | 14144 | 71120 | 395136 |
See also
Further reading
Grosswald, Emil (1985). Representations of integers as sums of squares. Springer-Verlag. ISBN0387961267.
External links
- Weisstein, Eric W. . MathWorld.
- Sloane, N.J.A. (ed.). . The On-Line Encyclopedia of Integer Sequences. OEIS Foundation.
- Sloane, N.J.A. (ed.). . The On-Line Encyclopedia of Integer Sequences. OEIS Foundation.