-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path047.js
More file actions
38 lines (33 loc) · 769 Bytes
/
047.js
File metadata and controls
38 lines (33 loc) · 769 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// Distinct primes factors
// https://projecteuler.net/problem=47
function primeFactors(n) {
var factors = [];
var d = 2, included = false;
while (n > 1) {
included = false;
while (n % d === 0) {
if (!included) factors.push(d);
included = true;
n = n/d;
}
d++;
if (d*d > n && n > 1) {
factors.push(n);
break;
}
}
return factors;
}
function consecutivePrimesStreak(length) {
var len = 0, cnt = 1;
while (len < length) {
if (primeFactors(cnt).length === length) {
len++;
} else {
len = 0;
}
cnt++;
}
return cnt - length;
}
console.log( consecutivePrimesStreak(4) );