P22396 [HackerRank] Pairwise sum and divide
提高-
题目描述

You are given an array of numbers. Let us denote the array with $\boldsymbol{A\left[\right]}$. Your task is very simple. You need to find the value returned by the function $\text{fun}(A)$.

fun(A)
sum = 0
for i = 1 to A.length
for j = i+1 to A.length
sum = sum + Floor((A[i]+A[j])/(A[i]*A[j]))
return sum

In short, this function takes all distinct pairs of indexes from the array and adds the value $\left\lfloor\frac{A[i]+A[j]}{A[i]\times A[j]}\right\rfloor$ to the sum. Your task is to find the sum.

Note: $\left\lfloor\frac{A}{B}\right\rfloor$ is the integer division function.

Input Format

The first line contains $\mathbf{T}$, the number of test cases to follow.

Each test case contains two lines: the first line contains $N$, the size of the array, and the second line contains $N$ integers separated by spaces.

Output Format

The output should contain exactly $\mathbf{T}$ lines where the $i^{th}$ line contains the answer for the $i^{th}$ test case.

Constraints

$1\leq T\leq15$

$1\leq N\leq2\times10^5$

$1\leq\text{Sum of}~N~\text{over all test cases}~\leq2\times10^5$

$1\leq A[i]\leq10^9$

Sample Input

2
3
4 2 3
3
1 4 1

Sample Output

0
4

Explanation

First Test Case: $\left\lfloor\frac{6}{8}\right\rfloor+\left\lfloor\frac{7}{12}\right\rfloor+\left\lfloor\frac{5}{6}\right\rfloor=0$

Second Test Case: $\left\lfloor\frac{5}{4}\right\rfloor+\left\lfloor\frac{2}{1}\right\rfloor+\left\lfloor\frac{5}{4}\right\rfloor=4$

输入格式

见题面

输出格式

见题面

样例输入
2 3 4 2 3 3 1 4 1
样例输出
0 4