Distinct Primes Factors
Find the first four consecutive integers to have four distinct prime factors each. What is the first of these numbers?
Problem Statement
This archive keeps the full statement, math, and original media on the page.
The first two consecutive numbers to have two distinct prime factors are: \begin {align*} 14 &= 2 \times 7\\ 15 &= 3 \times 5. \end {align*}
The first three consecutive numbers to have three distinct prime factors are: \begin {align*} 644 &= 2^2 \times 7 \times 23\\ 645 &= 3 \times 5 \times 43\\ 646 &= 2 \times 17 \times 19. \end {align*}
Find the first four consecutive integers to have four distinct prime factors each. What is the first of these numbers?
Problem 47: Distinct Primes Factors
Mathematical Development
Formal Development
Definition 1 (Distinct prime factor count). For a positive integer with canonical prime factorization , the number of distinct prime factors is .
Definition 2 (Consecutive run). A consecutive run of length with property starting at is a maximal sequence such that for all .
We seek .
Theorem 1 (Sieve computation of ). For all integers , the function can be computed simultaneously in time and space.
Proof. Initialize an array . For each : if then is prime (it has not been marked by any smaller prime), so for every multiple , increment by .
Correctness. Each prime dividing contributes exactly one increment to , since is a multiple of . Conversely, each increment to corresponds to a distinct prime divisor of . Hence after the sieve, equals the number of distinct prime factors.
Complexity. Each prime contributes increments. The total is:
where is the Meissel—Mertens constant. This is . Space is for the array.
Lemma 1 (Lower bound). If , then .
Proof. An integer with 4 distinct prime factors is at least where are primes. The minimum is attained by the four smallest primes: .
Lemma 2 (Sufficient search bound). The first four consecutive integers each with occur below .
Proof. By direct computation (see Theorem 2 below), the answer is .
Theorem 2. The first four consecutive integers each having exactly 4 distinct prime factors are .
Proof. We apply the sieve of Theorem 1 with , then scan for the first index where .
The factorizations are:
Each factorization is verified by confirming that are all prime (by trial division up to their respective square roots).
Minimality. The linear scan guarantees that no satisfies the four-consecutive condition. Indeed, the scan reports the first occurrence.
Editorial
We evaluate the function for every integer up to a fixed bound by a modified sieve: whenever a prime is encountered, each multiple of receives one increment in its distinct-factor count. After this preprocessing, a single left-to-right scan locates the first run of four consecutive integers whose counts are all equal to , and the first term of that run is returned.
Pseudocode
Algorithm: First Run of Four Integers with Four Distinct Prime Factors
Require: A search bound large enough to contain the first solution.
Ensure: The first integer in the earliest block of four consecutive integers each having exactly four distinct prime factors.
1: Initialize omega(n) ← 0 for every integer in the search range.
2: For each prime p, increment omega(m) for every multiple m of p.
3: Scan the integers in increasing order while maintaining the current streak length of values with omega(n) = 4.
4: When the streak length first reaches 4, return the initial value of that block.
Complexity Analysis
Proposition (Time complexity). The algorithm runs in time where .
Proof. Phase 1 (the sieve) dominates at by Theorem 1. Phase 2 is a single linear scan in time. The total is .
Proposition (Space complexity). The algorithm uses space.
Proof. The array of size is the sole data structure.
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 = 150000;
vector<int> dpf(LIMIT, 0);
for (int i = 2; i < LIMIT; i++) {
if (dpf[i] == 0) {
for (int j = i; j < LIMIT; j += i) {
dpf[j]++;
}
}
}
int consecutive = 0;
for (int i = 2; i < LIMIT; i++) {
if (dpf[i] == 4) {
consecutive++;
if (consecutive == 4) {
cout << i - 3 << endl;
return 0;
}
} else {
consecutive = 0;
}
}
return 0;
}
"""
Problem 47: Distinct Primes Factors
Find the first four consecutive integers each having exactly four
distinct prime factors.
"""
def solve():
LIMIT = 150000
dpf = [0] * LIMIT
for i in range(2, LIMIT):
if dpf[i] == 0: # i is prime
for j in range(i, LIMIT, i):
dpf[j] += 1
consecutive = 0
for i in range(2, LIMIT):
if dpf[i] == 4:
consecutive += 1
if consecutive == 4:
return i - 3
else:
consecutive = 0
answer = solve()
assert answer == 134043
print(answer)