Skip to main content
Back to problems
Leetcode
Medium
Math
Number Theory
Arrays
Find The Count Of Numbers Which Are Not Special

Count how many integers in a given range are not special, where special numbers are defined by a problem-specific numeric rule.

Acceptance 0%
Also Available On
Other platform versions and source mappings for the same problem.

Count the number of non-special integers in a range

gfg
Problem Statement

Problem

You are given a range of integers and a rule that marks some numbers in that range as special. Your task is to count how many numbers in the range are not special.

In the most common formulation of this problem, a number is special if it satisfies a certain divisor-based condition, and you must return the number of integers in the inclusive range that do not satisfy it.

Goal

Compute the count of non-special numbers efficiently for the provided range.

Notes

  • The range is inclusive.
  • A number may be special due to a property derived from its factors/divisors.
  • A direct check of every possible value can be too slow for large bounds, so an efficient counting approach is expected.

Input Format

  • A range described by two integers, typically l and r, with l <= r.
  • The exact special-number rule is part of the problem definition.

Input

clike

l r

Output Format

  • Return a single integer: the number of integers in the inclusive range [l, r] that are not special.

Output

clike

count

Constraints

  • 1 <= l <= r
  • Bounds are intended to be large enough that naive enumeration may be inefficient.
  • Use 64-bit arithmetic where needed.
Examples
Sample cases returned by the problem API.

Example 1

Input

l = 1, r = 10

Output

8

Explanation

If 2 numbers in the range are special, then the remaining 8 are not special. This example illustrates the counting objective.

Premium problem context

Unlock deeper context for this problem

Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.