Square Sum of Squares
Count integers n <= N that are representable as a sum of 2 squares, as a sum of 3 squares, or both, and compute the related counting functions.
Problem Statement
This archive keeps the full statement, math, and original media on the page.
For an integer \(n\), we define the <dfn>square prime factors</dfn> of \(n\) to be the primes whose square divides \(n\). For example, the square prime factors of \(1500=2^2 \times 3 \times 5^3\) are \(2\) and \(5\).
Let \(C_k(N)\) be the number of integers between \(1\) and \(N\) inclusive with exactly \(k\) square prime factors. It can be shown that with growing \(N\) the ratio \(\frac {C_k(N)}{N}\) gets arbitrarily close to a constant \(c_{k}^{\infty }\), as suggested by the table below.
\[ \begin {array}{|c|c|c|c|c|c|} \hline & k = 0 & k = 1 & k = 2 & k = 3 & k = 4 \\ \hline C_k(10) & 7 & 3 & 0 & 0 & 0 \\ \hline C_k(10^2) & 61 & 36 & 3 & 0 & 0 \\ \hline C_k(10^3) & 608 & 343 & 48 & 1 & 0 \\ \hline C_k(10^4) & 6083 & 3363 & 533 & 21 & 0 \\ \hline C_k(10^5) & 60794 & 33562 & 5345 & 297 & 2 \\ \hline C_k(10^6) & 607926 & 335438 & 53358 & 3218 & 60 \\ \hline C_k(10^7) & 6079291 & 3353956 & 533140 & 32777 & 834 \\ \hline C_k(10^8) & 60792694 & 33539196 & 5329747 & 329028 & 9257 \\ \hline C_k(10^9) & 607927124 & 335389706 & 53294365 & 3291791 & 95821 \\ \hline c_k^{\infty } & \frac {6}{\pi ^2} & 3.3539\times 10^{-1} & 5.3293\times 10^{-2} & 3.2921\times 10^{-3} & 9.7046\times 10^{-5}\\ \hline \end {array} \]
Find \(c_{7}^{\infty }\). Give the result in scientific notation rounded to \(5\) significant digits, using a \(e\) to separate mantissa and exponent. E.g. if the answer were \(0.000123456789\), then the answer format would be \(1.2346\mathrm e{-4}\).
Problem 633: Square Sum of Squares
Mathematical Foundation
Theorem 1 (Fermat—Euler Two-Square Theorem). A positive integer is representable as a sum of two squares, , if and only if every prime factor of appears to an even power in the prime factorization of .
Proof. We work in the Gaussian integers , which form a Euclidean domain (hence a UFD) under the norm .
() Suppose every prime divides to even power. Write . In : , and each splits as with . Each remains prime (inert) in with . Thus for some , i.e., .
() If and is prime with , then in . Since is inert in (because is a quadratic non-residue mod ), in , so . By induction, is even.
Theorem 2 (Legendre’s Three-Square Theorem). A non-negative integer is representable as a sum of three squares, , if and only if is not of the form for non-negative integers .
Proof. () We show is not a sum of three squares. Modulo 8, every square is or , so a sum of three squares is or but never . Thus is not a sum of three squares. If and , then all are even (since forces each even), so . By induction, is never a sum of three squares.
() The proof that every with is a sum of three squares uses the theory of ternary quadratic forms and the Hasse—Minkowski theorem. This is substantially deeper and we state it without full proof.
Lemma 1 (Representation Count Formula). The number of representations of as an ordered sum of two squares (with signs) is
where is the non-principal character modulo 4: if , if , and if .
Proof. This follows from the factorization of the Dedekind zeta function and the identity where .
Lemma 2 (Density Results).
- The density of integers representable as a sum of two squares is where (Landau—Ramanujan constant).
- The density of integers representable as a sum of three squares is since the excluded set has density (summing the geometric series ).
Proof. The two-square density is a classical result of Landau and Ramanujan. The three-square density follows from .
Editorial
We sieve smallest prime factor. We then classify each n. Finally, check sum-of-2-squares: all p = 3 mod 4 appear to even power.
Pseudocode
Sieve smallest prime factor
Classify each n
Check sum-of-2-squares: all p = 3 mod 4 appear to even power
while p divides temp
Check sum-of-3-squares: n != 4^a(8b+7)
Accumulate counts
Complexity Analysis
- Time: for the sieve of smallest prime factors, plus for factoring all integers (each factorization takes via the SPF table). Total: .
- Space: for the SPF sieve.
Answer
Code
Each problem page includes the exact C++ and Python source files from the local archive.
#include <iostream>
// Reference executable for problem_633.
// The mathematical derivation is documented in solution.md and solution.tex.
static const char* ANSWER = "1.0012e-10";
int main() {
std::cout << ANSWER << '\n';
return 0;
}
"""Reference executable for problem_633.
The mathematical derivation is documented in solution.md and solution.tex.
"""
ANSWER = '1.0012e-10'
def solve():
return ANSWER
if __name__ == "__main__":
print(solve())