Preparando MOJI
You have an array $$$a$$$ of length $$$n$$$.
Your task is to answer $$$q$$$ queries: given $$$x,y$$$, find the number of pairs $$$i$$$ and $$$j$$$ ($$$1 \le i < j \le n$$$) that both $$$a_i + a_j = x$$$ and $$$a_i \cdot a_j = y$$$.
That is, for the array $$$[1,3,2]$$$ and asking for $$$x=3,y=2$$$ the answer is $$$1$$$:
The first line contains one integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases.
The second line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 2\cdot 10^5$$$) — the length of the array $$$a$$$.
The third line of each test case contains $$$n$$$ integers $$$a_1,a_2,\dots,a_n$$$ ($$$1 \le |a_i| \le 10^9$$$) — array $$$a$$$.
The fourth line of each test case contains the integer $$$q$$$ ($$$1 \le q \le 2\cdot 10^5$$$) — the number of requests.
The next $$$q$$$ lines contain two numbers each $$$x$$$ and $$$y$$$ ($$$1 \le |x|\le 2\cdot 10^9,1\le |y|\le 10^{18}$$$) — request.
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$. This is also guaranteed for the sum of $$$q$$$ values.
For each test case print a line with $$$q$$$ numbers — the answers to the queries.
331 3 243 25 63 15 541 1 1 112 161 4 -2 3 3 332 -8-1 -27 12
1 1 0 0 6 1 1 3
For the first test case, let's analyze each pair of numbers separately:
In the second test case, all combinations of pairs are suitable.