P21 · 2 seconds · 256 MB
Count Primes
Return the number of **primes strictly less than** `n`. `n` may be 0 or 1; the answer is then 0.
function countPrimes(n) → number
CONSTRAINTS
- 0 ≤ n ≤ 5000
Input: n = 10
Output: 4
2, 3, 5, 7.
Input: n = 0
Output: 0
Input: n = 2
Output: 0
No prime is < 2.
1
2
3
4
5
6
7
8
Arena judges JavaScript in a Web Worker (1s wall-clock, then TLE). Samples are public; submit runs hidden tests too. C++/Python is a later swarm package.