An Engineers' Dream Come True
Define n to be an engineer's paradise if: 1. (n-9, n-3, n+3, n+9) are four consecutive primes (a "triple-pair" of sexy primes, each consecutive pair differing by exactly 6). 2. n-8, n-4, n, n+4, n+...
Problem Statement
This archive keeps the full statement, math, and original media on the page.
Consider the number \(6\). The divisors of \(6\) are: \(1,2,3\) and \(6\).
Every number from \(1\) up to and including \(6\) can be written as a sum of distinct divisors of \(6\):
\(1=1\), \(2=2\), \(3=1+2\), \(4=1+3\), \(5=2+3\), \(6=6\).
A number \(n\) is called a practical number if every number from \(1\) up to and including \(n\) can be expressed as a sum of distinct divisors of \(n\).
A pair of consecutive prime numbers with a difference of six is called a sexy pair (since "sex" is the Latin word for "six"). The first sexy pair is \((23, 29)\).
We may occasionally find a triple-pair, which means three consecutive sexy prime pairs, such that the second member of each pair is the first member of the next pair.
We shall call a number \(n\) such that:
-
\((n-9, n-3)\), \((n-3,n+3)\), \((n+3, n+9)\) form a triple-pair, and
-
the numbers \(n-8\), \(n-4\), \(n\), \(n+4\) and \(n+8\) are all practical,
an engineersâ
Find the sum of the first four engineersâ
Problem 263: An Engineers’ Dream Come True
Mathematical Foundation
Definition. A positive integer is practical if every integer can be represented as a sum of distinct divisors of .
Theorem 1 (Stewart’s criterion). A positive integer is practical if and only if is even and, writing with , we have for each :
where denotes the sum-of-divisors function.
Proof. See B. M. Stewart, “Sums of distinct divisors,” Amer. J. Math. 76 (1954), 779—785. The forward direction: if , then the integer cannot be represented. The reverse: if the condition holds for all , an inductive construction shows every integer up to (hence up to ) is representable.
Lemma 1 (Modular constraints on ). If are all primes greater than 5, then or .
Proof.
- Modulo 2: The four values , must be odd, so is even.
- Modulo 3: Since and , all four values are . For none to be divisible by 3, we need .
- Modulo 5: The residues modulo 5 are . For none to be , we need .
Combining: , , . By the Chinese Remainder Theorem, or .
Lemma 2 (Consecutivity conditions). For the four primes to be consecutive, the six intermediate odd values must all be composite.
Proof. Since is even, the only integers strictly between consecutive members of that could be prime are the odd ones: (between and ), (between and ), and (between and ). All must be composite for consecutivity.
Editorial
Definitions: i.e., (p, p+6), (p+6, p+12), (p+12, p+18) with all four consecutive primes. (1) n-9, n-3, n+3, n+9 are all prime AND are four consecutive primes (no primes between them: n-7, n-5, n-1, n+1, n+5, n+7 all composite) (2) n-8, n-4, n, n+4, n+8 are all practical numbers Key observations:. We sieve primes up to 1.2 * 10^9 using Sieve of Eratosthenes.
Pseudocode
Sieve primes up to 1.2 * 10^9 using Sieve of Eratosthenes
results = []
return sum(results)
Complexity Analysis
- Time: for the Sieve of Eratosthenes up to . The main loop iterates over candidates. Each practical-number test factors in and checks Stewart’s criterion in . Total: .
- Space: for the prime sieve bitmap.
Answer
Code
Each problem page includes the exact C++ and Python source files from the local archive.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
/*
* Problem 263: An Engineers' Dream Come True
*
* Find first 4 "engineers' paradises" n such that:
* - n-9, n-3, n+3, n+9 are all prime (sexy prime quadruplet)
* - (n-9, n-3), (n-3, n+3), (n+3, n+9) are CONSECUTIVE prime pairs
* (no primes between them: n-7, n-5, n-1, n+1, n+5, n+7 all composite)
* - n-8, n-4, n, n+4, n+8 are all practical numbers
*
* n ≡ 10 or 20 (mod 30).
*
* Answer: 2039506520
*/
const int LIMIT = 1200000010;
vector<bool> is_prime_sieve;
void build_sieve() {
is_prime_sieve.assign(LIMIT + 1, true);
is_prime_sieve[0] = is_prime_sieve[1] = false;
for (ll i = 2; i * i <= LIMIT; i++) {
if (is_prime_sieve[i]) {
for (ll j = i * i; j <= LIMIT; j += i)
is_prime_sieve[j] = false;
}
}
}
bool is_practical(ll n) {
if (n <= 0) return false;
if (n == 1) return true;
if (n % 2 != 0) return false;
vector<pair<ll,int>> factors;
ll temp = n;
for (ll d = 2; d * d <= temp; d++) {
if (temp % d == 0) {
int e = 0;
while (temp % d == 0) { temp /= d; e++; }
factors.push_back({d, e});
}
}
if (temp > 1) factors.push_back({temp, 1});
sort(factors.begin(), factors.end());
if (factors[0].first != 2) return false;
ll sigma = 1;
for (int i = 0; i < (int)factors.size(); i++) {
ll p = factors[i].first;
int a = factors[i].second;
if (i == 0) {
ll pw = 1;
for (int j = 0; j <= a; j++) pw *= p;
sigma = (pw - 1) / (p - 1);
} else {
if (p > 1 + sigma) return false;
ll pw = 1;
for (int j = 0; j <= a; j++) pw *= p;
sigma *= (pw - 1) / (p - 1);
}
}
return true;
}
int main() {
fprintf(stderr, "Building sieve up to %d...\n", LIMIT);
build_sieve();
fprintf(stderr, "Sieve done.\n");
vector<ll> results;
for (ll n = 10; n <= 1200000000LL && (int)results.size() < 4; n += 10) {
int r = n % 30;
if (r != 10 && r != 20) continue;
// Check four primes
if (!is_prime_sieve[n-9] || !is_prime_sieve[n+9] ||
!is_prime_sieve[n-3] || !is_prime_sieve[n+3])
continue;
// Check consecutive: no primes between the pairs
// n-7, n-5 must be composite (between n-9 and n-3)
// n-1, n+1 must be composite (between n-3 and n+3)
// n+5, n+7 must be composite (between n+3 and n+9)
if (is_prime_sieve[n-7] || is_prime_sieve[n-5] ||
is_prime_sieve[n-1] || is_prime_sieve[n+1] ||
is_prime_sieve[n+5] || is_prime_sieve[n+7])
continue;
// Check five practical numbers
if (is_practical(n-8) && is_practical(n-4) &&
is_practical(n) && is_practical(n+4) &&
is_practical(n+8)) {
results.push_back(n);
fprintf(stderr, "Found n = %lld (%lu/4)\n", n, results.size());
}
}
ll ans = 0;
for (ll x : results) ans += x;
cout << ans << endl;
return 0;
}
"""
Problem 263: An Engineers' Dream Come True
Definitions:
- Practical number: every integer 1..n is a sum of distinct divisors of n.
- Sexy pair: a pair of CONSECUTIVE primes differing by 6. First: (23, 29).
- Triple-pair: three consecutive sexy pairs where second member = first of next.
i.e., (p, p+6), (p+6, p+12), (p+12, p+18) with all four consecutive primes.
- Engineers' paradise: n such that:
(1) n-9, n-3, n+3, n+9 are all prime AND are four consecutive primes
(no primes between them: n-7, n-5, n-1, n+1, n+5, n+7 all composite)
(2) n-8, n-4, n, n+4, n+8 are all practical numbers
Key observations:
- n must be congruent to 10 or 20 (mod 30).
- The four values are: 219869980, 312501820, 360613700, 1146521020.
Answer: 2039506520
"""
import math
def sieve_primes(limit):
"""Simple sieve of Eratosthenes returning a boolean array."""
is_prime = bytearray([1]) * (limit + 1)
is_prime[0] = is_prime[1] = 0
for i in range(2, int(math.isqrt(limit)) + 1):
if is_prime[i]:
for j in range(i*i, limit + 1, i):
is_prime[j] = 0
return is_prime
def is_practical(n):
"""Check if n is a practical number using Stewart's criterion."""
if n <= 0: return False
if n == 1: return True
if n % 2 != 0: return False
factors = []
temp = n
d = 2
while d * d <= temp:
if temp % d == 0:
exp = 0
while temp % d == 0:
temp //= d
exp += 1
factors.append((d, exp))
d += 1
if temp > 1:
factors.append((temp, 1))
factors.sort()
if factors[0][0] != 2: return False
sigma_product = 1
for i, (p, a) in enumerate(factors):
if i == 0:
sigma_product = (p ** (a + 1) - 1) // (p - 1)
else:
if p > 1 + sigma_product: return False
sigma_product *= (p ** (a + 1) - 1) // (p - 1)
return True
def solve():
LIMIT = 1_200_000_000
print("Sieving primes...", flush=True)
is_prime = sieve_primes(LIMIT + 10)
print("Sieve done.", flush=True)
results = []
n = 10
while n <= LIMIT and len(results) < 4:
r = n % 30
if r == 10 or r == 20:
# Check four primes
if (is_prime[n - 9] and is_prime[n - 3] and
is_prime[n + 3] and is_prime[n + 9]):
# Check consecutive: no primes between the pairs
if not (is_prime[n-7] or is_prime[n-5] or
is_prime[n-1] or is_prime[n+1] or
is_prime[n+5] or is_prime[n+7]):
# Check five practical numbers
if (is_practical(n - 8) and is_practical(n - 4) and
is_practical(n) and is_practical(n + 4) and
is_practical(n + 8)):
results.append(n)
print(f"Found n = {n} ({len(results)}/4)", flush=True)
n += 10
print(sum(results))
if __name__ == "__main__":
solve()