#C6124. Count Perfect Squares in an Interval

    ID: 49850 Type: Default 1000ms 256MiB

Count Perfect Squares in an Interval

Count Perfect Squares in an Interval

Given two integers \(c\) and \(d\), count the number of perfect square integers within the interval \([c, d]\) (inclusive). A number \(n\) is a perfect square if there exists an integer \(m\) such that \(n = m^2\). For example, in the interval \([1, 10]\), the perfect squares are 1, 4, and 9, so the answer is 3.

Note that if \(c > d\), then the interval is invalid and the result should be 0. Use the mathematical functions to calculate the square roots and round appropriately with the formulas:

  • \(m = \sqrt{n}\)
  • \(start = \lceil \sqrt{c} \rceil\)
  • \(end = \lfloor \sqrt{d} \rfloor\)

The answer will be \(\max(0, end - start + 1)\) if \(c \leq d\), otherwise 0.

inputFormat

The input consists of two space-separated integers \(c\) and \(d\) on a single line from standard input.

outputFormat

Output a single integer representing the count of perfect square numbers in the interval \([c, d]\).

## sample
1 10
3

</p>