Difference of squares

3.5

19 votes
Operators, C++, Basic Programming, Basic Math, Modulo arithmetic, Math
Problem

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=P2Q2 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

1T1051L, R109

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

Numbers in the Range [1,5] which can be written as the difference of two squares are : 1,3,4,5. Hence, the answer is 4.

Editor Image

?