#P9231. Count Numbers Representable as a Difference of Squares
Count Numbers Representable as a Difference of Squares
Count Numbers Representable as a Difference of Squares
Given two integers \(L\) and \(R\), count how many integers \(x\) within the closed interval \([L, R]\) can be expressed as a difference of two squares, i.e., there exist integers \(y\) and \(z\) such that
\(x = y^2 - z^2\)
It is known that any integer \(x\) can be represented in this form if and only if \(x \not\equiv 2 \pmod{4}\). In other words, all odd numbers and even numbers divisible by 4 have such a representation.
inputFormat
The input consists of a single line containing two integers \(L\) and \(R\) (\(L \le R\)).
For example:
1 10
outputFormat
Output the number of integers \(x\) in the interval \([L, R]\) that can be represented as a difference of two squares.
For the sample above, the correct output is:
7
sample
1 10
7