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}}
… excerpt ends here. Continue reading the full article.

