All problems
0196MediumArrayMathEnumerationNumber TheoryPrimality TestSieve TheoryPrime Number Sieve

Indivisible Catalogue Numbers

Tracked in this browser only
Write code

Trains the technique from

LeetCode 204Count Primes

This is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.

Same function shape, different story and different numbers.

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 is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

Python
def count_indivisible_codes(limit: int) -> int:
Java
public int countIndivisibleCodes(int limit)
September 7
Apply