All practice tasks

Coding (Algo)

Count Prime Shard Sizes

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

4

Example 2

{
  "n": 2
}

Returns

1

Required complexity

O(n log log(n + 2)) time and O(n) auxiliary space

What this task practices

Count Prime Shard Sizes is a coding (algo) interview exercise that trains prompt interpretation, explicit assumptions, a concrete response, and a clear explanation of tradeoffs. The catalog marks it as medium difficulty. It focuses on Technical Reasoning, Testing, Validation. The signed-in workspace provides the tools for the round and evaluates the attempt against task-specific criteria. Reference solutions, hidden checks, evaluator instructions, and candidate work remain private.

Sign in to startThe workspace and evaluation open after sign in.