Difference of squares
Practice
3.5 (19 votes)
Operators
C++
Basic programming
Basic math
Modulo arithmetic
Math
Problem
88% Success 5101 Attempts 20 Points 1s Time Limit 256MB Memory 1024 KB Max Code

You are given two positive integers \(L\) and \(R\). Find the number of integers in the range \([L,\ R]\) that can be represented as the difference of two squares. In other words, find the number of integers \(X\) in the range \([L,\ R]\) such that \(X = P^2 - Q^2\) where \(P\) and \(R\) are integers.

Input format

  • The first line contains \(T\) denoting the number of test cases.
  • Each of the next \(T\) lines contain two integers \(L\) and \(R\)..

Output format

For each test case, you are required to print exactly \(T\) lines each containing only 1 positive integer.

Constraints

\(1 \leq T \leq 10^5\\ 1 \leq L,\ R \leq 10^9\)

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:20
11 votes
Tags:
OperatorMathematicsApprovedEasyMathamatics
Points:20
1 votes
Tags:
Easy
Points:20
1 votes
Tags:
EasySimple-math