#P9854. Pair Sum and Perfect Square
Pair Sum and Perfect Square
Pair Sum and Perfect Square
Problem Description
A permutation of elements is an array of numbers from to such that each number occurs exactly one times in it. Given a permutation of elements, there are queries to be made. Each query provides two integers and , asking how many pairs satisfy and is a square number. A square number is the product of some integer with itself. For example, is a square number, since it can be written as .
Input
The first line contains an integer , representing the number of test cases. For each test case, the input consists of lines: The first line contains an integer , representing the length of permutation . The second line contains integers , representing the elements of permutation . The third line contains an integer , indicating the number of queries. The next lines each contain two integers and , representing the range of each query.
Output
For each query in each test case, output one line containing an integer, representing the answer.
Sample Input
1
8
5 7 4 1 8 6 2 3
10
4 5
2 6
1 8
2 7
4 8
3 8
4 7
1 5
2 5
3 7
Sample Output
1
1
5
2
3
3
1
2
1
1
Source
2023“钉耙编程”中国大学生算法设计超级联赛(6)