Count Primes
Real-world version: Indivisible Catalogue NumbersThe statement here is our own: the same inputs, outputs and technique.
A parts depot gives every stock item a whole-number catalogue code. The stocktaking team calls a code indivisible when the code is 2 or larger and no whole number other than 1 and the code itself divides it exactly.
A clerk is auditing the codes below a cut-off limit. Report how many indivisible codes are smaller than limit. Codes equal to limit are outside the audit window and must not be counted, and when limit is so small that the window holds nothing, the tally is 0.
Examples
Example 1
- Input
- limit = 25
- Output
- 9
The indivisible codes under the cut-off are 2, 3, 5, 7, 11, 13, 17, 19 and 23, so the clerk records nine of them.
Example 2
- Input
- limit = 3
- Output
- 1
Only the code 2 sits under the cut-off. The code 3 equals the cut-off, so it stays out of the window.
Example 3
- Input
- limit = 97
- Output
- 24
Twenty-four codes below 97 have no divisor other than 1 and themselves; 97 itself is indivisible but is excluded by the cut-off.
Constraints
- 0 <= limit <= 5 * 10^6
The signature
The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.
def count_indivisible_codes(limit: int) -> int:public int countIndivisibleCodes(int limit)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 12 test cases: 12 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's
More on the same topics
- Maximum Score with Co-Prime ElementReal-world version: Best Pick Plus What It Leaves CoprimeHard
- Find Greatest Common Divisor of ArrayReal-world version: Sprocket Extremes Common DivisorEasy
- Make K-Subarray Sums EqualReal-world version: Balancing the Carousel SweepsMedium
- Minimum Jumps to Reach End via Prime TeleportationReal-world version: Relay Hops Along the Valve LineMedium