Divisor Square Sum
For a positive integer n, let sigma_2(n) denote the sum of the squares of the divisors of n: sigma_2(n) = sum_(d | n) d^2 For example, sigma_2(10) = 1^2 + 2^2 + 5^2 + 10^2 = 130. Find the sum of al...
Problem Statement
This archive keeps the full statement, math, and original media on the page.
For a positive integer \(n\), let \(\sigma _2(n)\) be the sum of the squares of its divisors. For example, \[\sigma _2(10) = 1 + 4 + 25 + 100 = 130.\] Find the sum of all \(n\), \(0 < n < 64\,000\,000\) such that \(\sigma _2(n)\) is a perfect square.
Problem 211: Divisor Square Sum
Mathematical Development
Definition 1. For , the divisor power sum function is . The case gives the sum-of-squares-of-divisors function.
Theorem 1 (Multiplicativity of ). The function is multiplicative: if , then .
Proof. Let with . We claim the map defined by is a bijection.
Surjectivity. Let . Write . Since , each prime divides at most one of . Set and . Then , , and .
Injectivity. If with and , then since implies , we have . By symmetry , so and thus .
Therefore:
Lemma 1 (Geometric sum for prime powers). For a prime and integer ,
Proof. The divisors of are precisely . Hence . This is a finite geometric series with first term , common ratio , and terms, yielding the closed form .
Proposition 1 (Overflow bound). For , we have where is the number of divisors. Since for any , and empirically for , unsigned 64-bit integers suffice.
Theorem 2 (Divisor sieve correctness). Let . Define the array by initializing for all , then for each and each multiple with , executing . Upon completion, for all .
Proof. After the sieve terminates, . Since , every divisor of satisfies , so the sum ranges over exactly the divisor set of . Thus .
Lemma 2 (Perfect square detection). A nonnegative integer is a perfect square if and only if . Integer square root can be computed exactly via Newton’s method or built-in isqrt.
Editorial
We compute sigma_2 via divisor sieve. Finally, check perfect squares and accumulate. We first generate the primes required by the search, then enumerate the admissible combinations and retain only the values that satisfy the final test.
Pseudocode
Compute sigma_2 via divisor sieve
Check perfect squares and accumulate
Complexity Analysis
Time. The sieve loop executes iterations. By the harmonic number estimate , this sum equals . The perfect-square check loop runs in . Total time complexity: .
Space. The array stores unsigned 64-bit values, requiring bytes. For , this is approximately 512 MB. Auxiliary space is . Total: .
Answer
Code
Each problem page includes the exact C++ and Python source files from the local archive.
#include <bits/stdc++.h>
using namespace std;
int main() {
const int N = 64000000;
vector<unsigned long long> sigma2(N, 0);
for (long long d = 1; d < N; d++) {
long long d2 = d * d;
for (long long k = d; k < N; k += d)
sigma2[k] += d2;
}
long long answer = 0;
for (int n = 1; n < N; n++) {
unsigned long long s = sigma2[n];
unsigned long long r = (unsigned long long)sqrt((double)s);
while (r * r > s) r--;
while ((r + 1) * (r + 1) <= s) r++;
if (r * r == s)
answer += n;
}
cout << answer << endl;
return 0;
}
import math
import numpy as np
def solve():
N = 64_000_000
sigma2 = np.zeros(N, dtype=np.uint64)
for d in range(1, N):
sigma2[d::d] += np.uint64(d * d)
answer = 0
for n in range(1, N):
s = int(sigma2[n])
r = math.isqrt(s)
if r * r == s:
answer += n
print(answer)
if __name__ == "__main__":
solve()