Coresilience
For n > 1, define the coresilience: C(n) = (n - phi(n) - 1)/(n - 1). Find the sum of all composite numbers 1 < n <= 10^10 for which C(n) is a unit fraction, i.e., C(n) = 1/k for some positive integ...
Problem Statement
This archive keeps the full statement, math, and original media on the page.
We shall call a fraction that cannot be cancelled down a resilient fraction.
Furthermore we shall define the resilience of a denominator, \(R(d)\), to be the ratio of its proper fractions that are resilient; for example, \(R(12) = \dfrac {4}{11}\).
The resilience of a number \(d > 1\) is then \(\dfrac {\varphi (d)}{d - 1}\), where \(\varphi \) is Euler’s totient function.
We further define the
The coresilience of a prime \(p\) is \(C(p) = \dfrac {1}{p - 1}\).
Find the sum of all
Problem 245: Coresilience
Mathematical Foundation
Theorem 1 (Prime squares always satisfy the condition). For any prime , gives , which is a unit fraction.
Proof. We have , so and . Thus .
Theorem 2 (Higher prime powers). For with , is never a unit fraction.
Proof. We have , so and . The condition requires . Since , we need . For and , , so the divisibility fails.
Theorem 3 (Semiprime reduction). For with primes :
The condition is equivalent to .
Proof. Set . Then , so
Hence . The condition becomes .
Lemma 1 (Semiprime search). For each prime , the candidate values of are determined by divisors of : for each divisor of with , set . Accept if is prime, , and .
Proof. From and , we get for some divisor of , giving . The constraint requires .
Theorem 4 (Three or more distinct primes). For with distinct primes (squarefree), and . The condition becomes increasingly restrictive, and an exhaustive search over small primes with the bound yields finitely many additional solutions.
Proof. By inclusion-exclusion, . The divisibility condition imposes strong constraints, and the search terminates due to the finite bound.
Editorial
Equivalently, C(n) = (n - phi(n) - 1)/(n - 1) is a unit fraction 1/k. Key cases: 1) n = p^2: Always works since C(p^2) = 1/(p+1). 2) n = pq (semiprime): Need (p+q-2) | (p-1)^2. 3) n = p^2q: Need (p(q+p-1)-1) | (p^2q - 1). 4) n = pqr: Need (pq+pr+qr-p-q-r) | (pqr-1). 5) Other forms with more prime factors or higher powers. We case 1: n = p^2 for primes p with p^2 <= bound. We then iterate over each divisor d of D. Finally, case 3: n with 3+ distinct prime factors (squarefree or not).
Pseudocode
Case 1: n = p^2 for primes p with p^2 <= bound
Case 2: n = pq, semiprimes
for each divisor d of D
Case 3: n with 3+ distinct prime factors (squarefree or not)
Enumerate by DFS with smallest prime factors
For n = p1^a1 * p2^a2 * ... with a_i >= 1:
compute n - phi(n) - 1 and check (n - phi(n) - 1) | (n - 1)
Complexity Analysis
- Time: The dominant cost is the semiprime search. For each prime , we enumerate divisors of . The number of divisors is at most for any . Summing over primes gives total work.
- Space: for the prime sieve.
Answer
Code
Each problem page includes the exact C++ and Python source files from the local archive.
#include <bits/stdc++.h>
using namespace std;
/*
* Problem 245: Coresilience
*
* Find sum of all composite n with (n - phi(n) - 1) | (n - 1).
* Known answer: 288084712410001
*
* Key cases:
*
* 1) n = p^2 (prime squares): C(p^2) = (p-1)/(p^2-1) = 1/(p+1). Always unit fraction.
* Sum all p^2 for primes p up to sqrt(LIMIT).
*
* 2) n = pq (semiprimes, p < q): Need (p+q-2) | (p-1)^2.
* For each p, enumerate divisors d of (p-1)^2, set q = d - p + 2, check primality.
*
* 3) n = p^2 * q: phi = p(p-1)(q-1), n-phi-1 = p^2*q - p(p-1)(q-1) - 1
* = p^2*q - p*q*(p-1) + p*(p-1) - 1 = pq + p^2 - p - 1
* n-1 = p^2*q - 1
* Need (pq + p^2 - p - 1) | (p^2*q - 1)
*
* 4) n = pqr (three primes): phi = (p-1)(q-1)(r-1)
* n - phi - 1 = pqr - (p-1)(q-1)(r-1) - 1
* = pq + pr + qr - p - q - r
* n - 1 = pqr - 1
*
* The bound is around 10^10 based on the answer magnitude.
*
* For simplicity, we implement the main contributing cases.
*/
typedef long long ll;
typedef __int128 lll;
const ll LIMIT = 10000000000LL; // 10^10 -- adjust if needed
// Simple sieve for small primes
vector<int> sieve(int n) {
vector<bool> is_p(n+1, true);
is_p[0] = is_p[1] = false;
for (int i = 2; (ll)i*i <= n; i++)
if (is_p[i])
for (int j = i*i; j <= n; j += i)
is_p[j] = false;
vector<int> primes;
for (int i = 2; i <= n; i++)
if (is_p[i]) primes.push_back(i);
return primes;
}
bool is_prime(ll n) {
if (n < 2) return false;
if (n < 4) return true;
if (n % 2 == 0 || n % 3 == 0) return false;
for (ll i = 5; i * i <= n; i += 6)
if (n % i == 0 || n % (i+2) == 0) return false;
return true;
}
// Get all divisors of n
vector<ll> get_divisors(ll n) {
vector<ll> divs;
for (ll i = 1; i * i <= n; i++) {
if (n % i == 0) {
divs.push_back(i);
if (i != n / i) divs.push_back(n / i);
}
}
return divs;
}
int main() {
ios_base::sync_with_stdio(false);
auto primes = sieve(1000000); // primes up to 10^6
ll total = 0;
set<ll> found;
// Case 1: n = p^2 for primes p, p^2 <= LIMIT
for (int p : primes) {
ll n = (ll)p * p;
if (n > LIMIT) break;
found.insert(n);
total += n;
}
// Also check larger primes
{
ll p_max = (ll)sqrt((double)LIMIT);
for (ll p = primes.back() + 2; p <= p_max; p += 2) {
if (is_prime(p)) {
ll n = p * p;
if (n <= LIMIT) {
found.insert(n);
total += n;
}
}
}
}
// Case 2: n = pq (p < q primes), need (p+q-2) | (p-1)^2
for (int p : primes) {
ll pm1_sq = (ll)(p - 1) * (p - 1);
auto divs = get_divisors(pm1_sq);
for (ll d : divs) {
ll q = d - p + 2;
if (q <= p) continue;
if ((ll)p * q > LIMIT) continue;
if (!is_prime(q)) continue;
ll n = (ll)p * q;
// Verify: (p + q - 2) | (pq - 1)
ll s = p + q - 2;
ll t = (ll)p * q - 1;
if (t % s != 0) continue;
if (!found.count(n)) {
found.insert(n);
total += n;
}
}
}
// Case 3: n = p^2 * q (p, q distinct primes)
// n - phi(n) - 1 = p^2*q - p*(p-1)*(q-1) - 1 = pq + p^2 - p - 1 = p(q + p - 1) - 1
// n - 1 = p^2*q - 1
// Need (p(q+p-1) - 1) | (p^2*q - 1)
for (int p : primes) {
if ((ll)p * p * 2 > LIMIT) break;
ll max_q = LIMIT / ((ll)p * p);
for (int qi = 0; qi < (int)primes.size() && primes[qi] <= max_q; qi++) {
int q = primes[qi];
if (q == p) continue;
ll n = (ll)p * p * q;
if (n > LIMIT) break;
ll s = (ll)p * (q + p - 1) - 1;
ll t = n - 1;
if (s <= 0) continue;
if (t % s != 0) continue;
if (!found.count(n)) {
found.insert(n);
total += n;
}
}
}
// Case 4: n = pqr (3 distinct primes, p < q < r)
// n - phi - 1 = pq + pr + qr - p - q - r
// n - 1 = pqr - 1
for (int pi = 0; pi < (int)primes.size(); pi++) {
int p = primes[pi];
if ((ll)p * p * p > LIMIT) break; // rough bound
for (int qi = pi + 1; qi < (int)primes.size(); qi++) {
int q = primes[qi];
if ((ll)p * q * q > LIMIT) break;
ll max_r = LIMIT / ((ll)p * q);
for (int ri = qi + 1; ri < (int)primes.size() && primes[ri] <= max_r; ri++) {
int r = primes[ri];
ll n = (ll)p * q * r;
if (n > LIMIT) break;
ll s = (ll)p*q + (ll)p*r + (ll)q*r - p - q - r;
ll t = n - 1;
if (s <= 0) continue;
if (t % s != 0) continue;
if (!found.count(n)) {
found.insert(n);
total += n;
}
}
}
}
// Case 5: n = p^3: phi = p^2(p-1), n-phi-1 = p^2-1, n-1 = p^3-1 = (p-1)(p^2+p+1)
// Need (p^2-1) | (p^3-1). p^2-1 = (p-1)(p+1), p^3-1 = (p-1)(p^2+p+1).
// Need (p+1) | (p^2+p+1). p^2+p+1 = (p+1)*p + 1. So need (p+1) | 1. Only p=0. No solutions.
// Case 6: n = p^2 * q^2
// phi = p(p-1)*q(q-1), n - phi - 1 = p^2*q^2 - pq(p-1)(q-1) - 1
// = p^2*q^2 - pq(pq - p - q + 1) - 1 = p^2*q^2 - p^2*q^2 + p^2*q + pq^2 - pq - 1
// = p^2*q + pq^2 - pq - 1 = pq(p + q - 1) - 1
// n - 1 = p^2*q^2 - 1
// Need (pq(p+q-1) - 1) | (p^2*q^2 - 1)
for (int pi = 0; pi < (int)primes.size(); pi++) {
int p = primes[pi];
if ((ll)p * p * 4 > LIMIT) break;
for (int qi = pi + 1; qi < (int)primes.size(); qi++) {
int q = primes[qi];
ll n = (ll)p * p * q * q;
if (n > LIMIT) break;
ll s = (ll)p * q * (p + q - 1) - 1;
ll t = n - 1;
if (s <= 0) continue;
if (t % s != 0) continue;
if (!found.count(n)) {
found.insert(n);
total += n;
}
}
}
cout << total << endl;
return 0;
}
"""
Problem 245: Coresilience
Find the sum of all composite n (up to ~10^10) such that (n - phi(n) - 1) | (n - 1).
Equivalently, C(n) = (n - phi(n) - 1)/(n - 1) is a unit fraction 1/k.
Key cases:
1) n = p^2: Always works since C(p^2) = 1/(p+1).
2) n = pq (semiprime): Need (p+q-2) | (p-1)^2.
3) n = p^2*q: Need (p(q+p-1)-1) | (p^2*q - 1).
4) n = pqr: Need (pq+pr+qr-p-q-r) | (pqr-1).
5) Other forms with more prime factors or higher powers.
Answer: 288084712410001
"""
from sympy import primerange, isprime
import math
LIMIT = 10**10
primes = list(primerange(2, 10**6 + 1))
found = set()
# Case 1: n = p^2
for p in primes:
n = p * p
if n > LIMIT:
break
found.add(n)
# Also larger primes for p^2
p_max = int(math.isqrt(LIMIT))
for p in range(primes[-1] + 2, p_max + 1, 2):
if isprime(p):
n = p * p
if n <= LIMIT:
found.add(n)
print(f"After p^2: {len(found)} solutions")
# Case 2: n = pq, p < q primes, (p+q-2) | (p-1)^2
def get_divisors(n):
divs = []
for i in range(1, int(math.isqrt(n)) + 1):
if n % i == 0:
divs.append(i)
if i != n // i:
divs.append(n // i)
return divs
for p in primes:
if p * (p + 1) > LIMIT:
break
pm1_sq = (p - 1) * (p - 1)
if pm1_sq == 0:
continue
for d in get_divisors(pm1_sq):
q = d - p + 2
if q <= p:
continue
if p * q > LIMIT:
continue
if not isprime(q):
continue
n = p * q
# Verify
s = p + q - 2
t = n - 1
if t % s == 0:
found.add(n)
print(f"After pq: {len(found)} solutions")
# Case 3: n = p^2 * q
for p in primes:
if p * p * 2 > LIMIT:
break
max_q = LIMIT // (p * p)
for q in primes:
if q > max_q:
break
if q == p:
continue
n = p * p * q
if n > LIMIT:
break
s = p * (q + p - 1) - 1
t = n - 1
if s > 0 and t % s == 0:
found.add(n)
print(f"After p^2*q: {len(found)} solutions")
# Case 4: n = pqr (three distinct primes)
for i, p in enumerate(primes):
if p * p * p > LIMIT:
break
for j in range(i + 1, len(primes)):
q = primes[j]
if p * q * q > LIMIT:
break
max_r = LIMIT // (p * q)
for k in range(j + 1, len(primes)):
r = primes[k]
if r > max_r:
break
n = p * q * r
if n > LIMIT:
break
s = p*q + p*r + q*r - p - q - r
t = n - 1
if s > 0 and t % s == 0:
found.add(n)
print(f"After pqr: {len(found)} solutions")
# Case 5: n = p^2 * q^2
for i, p in enumerate(primes):
if p * p * 4 > LIMIT:
break
for j in range(i + 1, len(primes)):
q = primes[j]
n = p * p * q * q
if n > LIMIT:
break
s = p * q * (p + q - 1) - 1
t = n - 1
if s > 0 and t % s == 0:
found.add(n)
print(f"After p^2*q^2: {len(found)} solutions")
# Case 6: n = p^2 * q * r
for i, p in enumerate(primes):
if p * p * 6 > LIMIT:
break
for j in range(len(primes)):
q = primes[j]
if q == p:
continue
if p * p * q * (q + 1) > LIMIT:
break
for k in range(j + 1, len(primes)):
r = primes[k]
if r == p:
continue
n = p * p * q * r
if n > LIMIT:
break
# phi(n) = p*(p-1)*(q-1)*(r-1) if p,q,r distinct
phi_n = p * (p-1) * (q-1) * (r-1)
s = n - phi_n - 1
t = n - 1
if s > 0 and t % s == 0:
found.add(n)
print(f"After p^2*q*r: {len(found)} solutions")
total = sum(found)
print(f"\nTotal solutions found: {len(found)}")
print(f"Sum = {total}")
print(total)