Ctrl K

Not Exactly Three Divisors

Medium
You are given two positive integers low and high. Count how many numbers from low to high inclusive have a number of positive divisors **other than** three (1 and the number itself both count as divisors). Checking every number and its divisors will not do: the range can be almost a billion long.
Example 1
low=1, high=10 → 8

Only 4 (1, 2, 4) and 9 (1, 3, 9) have exactly three divisors. The other 8 numbers count.

Example 2
low=20, high=30 → 10

Of the 11 numbers, only 25 (1, 5, 25) has exactly three divisors.

Constraints
  • 1 ≤ low ≤ high ≤ 10⁹
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsPrimes Below a Bound MediumPhoto Frames of the Same Shape MediumSegments on a Chart MediumChunks With a Common Divisor MediumSegments With a Given GCD Medium
loading Python…
Input
low=1, high=10
Expected
8

Run checks the first 3 tests in your browser. Submit checks all 79 tests on the server, hidden ones included.