CF1900D.Small GCD

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Let aa , bb , and cc be integers. We define function f(a,b,c)f(a, b, c) as follows:

Order the numbers aa , bb , cc in such a way that abca \le b \le c . Then return gcd(a,b)\gcd(a, b) , where gcd(a,b)\gcd(a, b) denotes the greatest common divisor (GCD) of integers aa and bb .

So basically, we take the gcd\gcd of the 22 smaller values and ignore the biggest one.

You are given an array aa of nn elements. Compute the sum of f(ai,aj,ak)f(a_i, a_j, a_k) for each ii , jj , kk , such that 1i<j<kn1 \le i < j < k \le n .

More formally, compute $$$$\sum_{i = 1}^n \sum_{j = i+1}^n \sum_{k =j +1}^n f(a_i, a_j, a_k). $$$$

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt ( 1t101 \le t \le 10 ). The description of the test cases follows.

The first line of each test case contains a single integer nn ( 3n81043 \le n \le 8 \cdot 10^4 ) — length of the array aa .

The second line of each test case contains nn integers, a1,a2,,ana_1, a_2, \ldots, a_n ( 1ai1051 \le a_i \le 10^5 ) — elements of the array aa .

It is guaranteed that the sum of nn over all test cases does not exceed 81048 \cdot 10^4 .

输出格式

For each test case, output a single number — the sum from the problem statement.

输入输出样例

  • 输入#1

    2
    5
    2 3 6 12 17
    8
    6 12 8 10 15 12 18 16

    输出#1

    24
    203

说明/提示

In the first test case, the values of ff are as follows:

  • i=1i=1 , j=2j=2 , k=3k=3 , f(ai,aj,ak)=f(2,3,6)=gcd(2,3)=1f(a_i,a_j,a_k)=f(2,3,6)=\gcd(2,3)=1 ;
  • i=1i=1 , j=2j=2 , k=4k=4 , f(ai,aj,ak)=f(2,3,12)=gcd(2,3)=1f(a_i,a_j,a_k)=f(2,3,12)=\gcd(2,3)=1 ;
  • i=1i=1 , j=2j=2 , k=5k=5 , f(ai,aj,ak)=f(2,3,17)=gcd(2,3)=1f(a_i,a_j,a_k)=f(2,3,17)=\gcd(2,3)=1 ;
  • i=1i=1 , j=3j=3 , k=4k=4 , f(ai,aj,ak)=f(2,6,12)=gcd(2,6)=2f(a_i,a_j,a_k)=f(2,6,12)=\gcd(2,6)=2 ;
  • i=1i=1 , j=3j=3 , k=5k=5 , f(ai,aj,ak)=f(2,6,17)=gcd(2,6)=2f(a_i,a_j,a_k)=f(2,6,17)=\gcd(2,6)=2 ;
  • i=1i=1 , j=4j=4 , k=5k=5 , f(ai,aj,ak)=f(2,12,17)=gcd(2,12)=2f(a_i,a_j,a_k)=f(2,12,17)=\gcd(2,12)=2 ;
  • i=2i=2 , j=3j=3 , k=4k=4 , f(ai,aj,ak)=f(3,6,12)=gcd(3,6)=3f(a_i,a_j,a_k)=f(3,6,12)=\gcd(3,6)=3 ;
  • i=2i=2 , j=3j=3 , k=5k=5 , f(ai,aj,ak)=f(3,6,17)=gcd(3,6)=3f(a_i,a_j,a_k)=f(3,6,17)=\gcd(3,6)=3 ;
  • i=2i=2 , j=4j=4 , k=5k=5 , f(ai,aj,ak)=f(3,12,17)=gcd(3,12)=3f(a_i,a_j,a_k)=f(3,12,17)=\gcd(3,12)=3 ;
  • i=3i=3 , j=4j=4 , k=5k=5 , f(ai,aj,ak)=f(6,12,17)=gcd(6,12)=6f(a_i,a_j,a_k)=f(6,12,17)=\gcd(6,12)=6 .

The sum over all triples is 1+1+1+2+2+2+3+3+3+6=241+1+1+2+2+2+3+3+3+6=24 .In the second test case, there are 5656 ways to choose values of ii , jj , kk . The sum over all f(ai,aj,ak)f(a_i,a_j,a_k) is 203203 .

首页