curriculum/challenges/english/blocks/project-euler-problems-1-to-100/5900f39c1000cf542c50feae.md
The first two consecutive numbers to have two distinct prime factors are:
<div style='padding-left: 4em;'> 14 = 2 × 715 = 3 × 5
</div>The first three consecutive numbers to have three distinct prime factors are:
<div style='padding-left: 4em;'> 644 = 2<sup>2</sup> × 7 × 23645 = 3 × 5 × 43
646 = 2 × 17 × 19
</div>Find the first four consecutive integers to have four distinct prime factors each. What is the first of these numbers?
distinctPrimeFactors(2, 2) should return a number.
assert(typeof distinctPrimeFactors(2, 2) === 'number');
distinctPrimeFactors(2, 2) should return 14.
assert.strictEqual(distinctPrimeFactors(2, 2), 14);
distinctPrimeFactors(3, 3) should return 644.
assert.strictEqual(distinctPrimeFactors(3, 3), 644);
distinctPrimeFactors(4, 4) should return 134043.
assert.strictEqual(distinctPrimeFactors(4, 4), 134043);
function distinctPrimeFactors(targetNumPrimes, targetConsecutive) {
return true;
}
distinctPrimeFactors(4, 4);
function distinctPrimeFactors(targetNumPrimes, targetConsecutive) {
const primeLimit = targetNumPrimes * targetConsecutive * 10000;
const numFactors = Array(primeLimit).fill(0);
let numConsecutive = 0;
for (let i = 2; i < primeLimit; i++) {
if (numFactors[i] === targetNumPrimes) {
// Current number is composite with target num factors
numConsecutive++;
if (numConsecutive === targetConsecutive) {
return i - numConsecutive + 1;
}
} else {
// Current number is not matching composite
numConsecutive = 0;
if (numFactors[i] === 0) {
// Current number is prime
for (let j = i; j < primeLimit; j += i) {
numFactors[j]++;
}
}
}
}
}