Number theory · Medium
A local capacity experiment considers prime-sized shard counts up to a supplied upper limit. The caller needs the number of choices, including the limit when it is prime. No list of prime numbers is required.
Return how many prime integers are at least two and no greater than the supplied limit.
Input
Call
- Implement solve(input) and return the result. The provided adapter handles JSON input and output.
Input shape
{ n: integer }
Fields
- n is an inclusive integer upper limit.
Output
Return value
- Return an integer count. Limits 0 and 1 return 0.
- A prime has exactly two positive divisors; 1 is not prime.
Constraints
- 0 <= n <= 2000000.
Examples
Example 1
{
"n": 10
}Returns
4Example 2
{
"n": 2
}Returns
1Required complexity
O(n log log(n + 2)) time and O(n) auxiliary space