Common Factors Between Two Sequences
Let varphi(n) denote Euler's totient function and sigma(n) denote the sum-of-divisors function. Define G(n) = gcd(varphi(n), sigma(n)). Compute sum_(n=1)^N G(n) for a given large N.
Problem Statement
This archive keeps the full statement, math, and original media on the page.
Let \(G(a, b)\) be the smallest non-negative integer \(n\) for which \(\gcd \)\((n^3 + b, (n + a)^3 + b)\) is maximized.
For example, \(G(1, 1) = 5\) because \(\gcd (n^3 + 1, (n + 1)^3 + 1)\) reaches its maximum value of \(7\) for \(n = 5\), and is smaller for \(0 \le n < 5\).
Let \(H(m, n) = \sum G(a, b)\) for \(1 \le a \le m\), \(1 \le b \le n\).
You are given \(H(5, 5) = 128878\) and \(H(10, 10) = 32936544\).
Find \(H(18, 1900)\).
Problem 489: Common Factors Between Two Sequences
Mathematical Foundation
Theorem 1 (Euler’s totient function). For ,
Proof. By inclusion-exclusion (or the Chinese Remainder Theorem). The integers in coprime to are those not divisible by any prime . By multiplicativity and inclusion-exclusion:
For a prime power , the integers in not coprime to are exactly the multiples of , numbering . So . By multiplicativity, the product formula follows.
Theorem 2 (Sum-of-divisors function). For ,
Proof. Since is multiplicative, it suffices to verify for prime powers. For , the divisors are , and their sum is . By multiplicativity of , the product formula holds.
Lemma 1 (GCD at primes). For an odd prime :
For : .
Proof. , . Since (as , and by the Euclidean algorithm ). For odd , is even, so . For , .
Lemma 2 (GCD at prime powers). For with odd and :
Note that since (all terms except the first are divisible by ). Therefore:
Proof. Since (as ), the factor drops out:
by the property when .
Theorem 3 (Non-multiplicativity of ). The function is NOT multiplicative. That is, does not in general imply .
Proof. Counterexample: , , , but . This happens to agree. A better counterexample: , , , but . Still agrees. The non-multiplicativity is more subtle and arises because in general (the GCD of products does not factor as a product of GCDs). Consider , , vs . Finding an explicit failure requires searching, but the theoretical non-multiplicativity is established by the fact that no general identity holds.
Editorial
Compute gcd(phi(n), sigma(n)) for positive integers n and analyze the results. phi(n) = Euler’s totient function, sigma(n) = sum of divisors. We totient sieve. We then sum-of-divisors sieve. Finally, compute GCDs and accumulate.
Pseudocode
Totient sieve
Sum-of-divisors sieve
Compute GCDs and accumulate
Complexity Analysis
- Time:
- Totient sieve: (standard Euler’s product sieve with primes from Eratosthenes).
- Sum-of-divisors sieve: (harmonic series summation: ).
- GCD computation: (each costs by the Euclidean algorithm).
- Total: .
- Space: for the and arrays.
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 LIMIT = 1000;
// Totient sieve
vector<long long> phi(LIMIT + 1);
iota(phi.begin(), phi.end(), 0);
for (int p = 2; p <= LIMIT; p++) {
if (phi[p] == p) { // p is prime
for (int m = p; m <= LIMIT; m += p) {
phi[m] = phi[m] / p * (p - 1);
}
}
}
// Sigma sieve (sum of divisors)
vector<long long> sigma(LIMIT + 1, 0);
for (int j = 1; j <= LIMIT; j++) {
for (int m = j; m <= LIMIT; m += j) {
sigma[m] += j;
}
}
// Sum of gcd(phi(n), sigma(n))
long long total = 0;
for (int n = 1; n <= LIMIT; n++) {
total += __gcd(phi[n], sigma[n]);
}
cout << "Sum of gcd(phi(n), sigma(n)) for n=1.." << LIMIT << ": " << total << endl;
// Display first few values
cout << "\nn | phi(n) | sigma(n) | gcd" << endl;
for (int n = 1; n <= 20; n++) {
cout << n << " | " << phi[n] << " | " << sigma[n]
<< " | " << __gcd(phi[n], sigma[n]) << endl;
}
return 0;
}
"""
Problem 489: Common Factors Between Two Sequences
Compute gcd(phi(n), sigma(n)) for positive integers n and analyze the results.
phi(n) = Euler's totient function, sigma(n) = sum of divisors.
"""
from math import gcd
def totient_sieve(limit: int) -> list:
"""Compute phi(n) for n = 0..limit using Euler's product sieve."""
phi = list(range(limit + 1))
for p in range(2, limit + 1):
if phi[p] == p: # p is prime
for m in range(p, limit + 1, p):
phi[m] = phi[m] // p * (p - 1)
return phi
def sigma_sieve(limit: int) -> list:
"""Compute sigma(n) = sum of divisors for n = 0..limit."""
sigma = [0] * (limit + 1)
for j in range(1, limit + 1):
for m in range(j, limit + 1, j):
sigma[m] += j
return sigma
def solve(limit: int):
"""Compute sum of gcd(phi(n), sigma(n)) for n = 1..limit."""
phi = totient_sieve(limit)
sig = sigma_sieve(limit)
total = 0
for n in range(1, limit + 1):
total += gcd(phi[n], sig[n])
return total
# Compute for small values and display
limit = 100
phi = totient_sieve(limit)
sig = sigma_sieve(limit)
print("n | phi(n) | sigma(n) | gcd(phi,sigma)")
print("-" * 45)
for n in range(1, 21):
g = gcd(phi[n], sig[n])
print(f"{n:2d} | {phi[n]:5d} | {sig[n]:6d} | {g}")
answer_100 = solve(100)
print(f"\nSum of gcd(phi(n), sigma(n)) for n=1..100: {answer_100}")
answer_1000 = solve(1000)
print(f"Sum of gcd(phi(n), sigma(n)) for n=1..1000: {answer_1000}")