Skip to content

Commit d6de59f

Browse files
authored
Create 3233-find-the-count-of-numbers-which-are-not-special.js
1 parent e8041d2 commit d6de59f

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/**
2+
* @param {number} l
3+
* @param {number} r
4+
* @return {number}
5+
*/
6+
const nonSpecialCount = function (l, r) {
7+
let res = 0
8+
for (
9+
let i = Math.floor(Math.sqrt(l)) - 10;
10+
i <= Math.floor(Math.sqrt(r)) + 10;
11+
i++
12+
) {
13+
if (isPrime(i) && l <= i * i && i * i <= r) {
14+
res += 1
15+
}
16+
}
17+
return r - l + 1 - res
18+
}
19+
20+
function isPrime(n) {
21+
if (n <= 1) {
22+
return false
23+
}
24+
if (n <= 3) {
25+
return true
26+
}
27+
if (n % 2 === 0 || n % 3 === 0) {
28+
return false
29+
}
30+
let i = 5
31+
while (i * i <= n) {
32+
if (n % i === 0 || n % (i + 2) === 0) {
33+
return false
34+
}
35+
i += 6
36+
}
37+
return true
38+
}

0 commit comments

Comments
 (0)