#CT0000063. Nhiều truy vấn đếm số chính phương (Multiple Perfect-Square Count Queries)
Nhiều truy vấn đếm số chính phương (Multiple Perfect-Square Count Queries)
Multiple Perfect-Square Count Queries
Version: Phuoc Hung OJ Extended
Problem Statement
You are given integer intervals. Query is described by two positive integers and with .
For each query, determine the number of perfect squares in . The queries are independent and must be answered in their input order.
Input
The first line contains the positive integer , the number of queries.
The next lines each contain two positive integers and .
Output
Print lines. Line contains the number of perfect squares in .
Subtasks
- Subtask 1 (20%): and .
- Subtask 2 (30%): and .
- Subtask 3 (50%): and .
Examples
Example 1
Input
4
1 10
15 35
36 36
37 63
Output
3
2
1
1
Explanation
The four intervals contain , , , and respectively. Thus the answers are .
Example 2
Input
4
1 1
2 3
99 100
100 121
Output
1
0
1
2
Explanation
contains ; contains no perfect square; contains only ; and contains both and .
Example 3
Input
3
1000000000000000000 1000000000000000000
999999998000000001 1000000000000000000
999999998000000002 999999999999999999
Output
1
2
0
Explanation
The two consecutive perfect squares nearest the upper limit are and . The first query contains the latter; the second contains both; the third lies strictly between them and contains none.