问题 B: Pair Sum and Perfect Square

内存限制:512 MB 时间限制:3 S
题面:传统 评测方式:文本比较 上传者:
提交:0 通过:0

题目描述

A permutation of n elements is an array of n numbers from 11 to n such that each number occurs exactly one times in it.

Given a permutation p of n elements, there are Q queries to be made.

Each query provides two integers L and R1LRn, asking how many pairs i,j satisfy Li<jR and pi+pj is a square number.

A square number is the product of some integer with itself. For example, 99 is a square number, since it can be written as 3232.

输入格式

The first line contains an integer TT5, representing the number of test cases.

For each test case, the input consists ofQ+3 lines:

The first line contains an integern(1n105, representing the length of permutation p.

The second line contains n integers p1,p2,...,pn1pin, representing the elements of permutation p.

The third line contains an integer Q1Q105, indicating the number of queries.

The next Q lines each contain two integers L and R1LRn, representing the range of each query.

输出格式

For each query in each test case, output one line containing an integer, representing the answer.

输入样例 复制

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

输出样例 复制

1
1
5
2
3
3
1
2
1
1