#include <stdio.h>
int gcd(int a, int b) {
if(a<b) {
int tmp=a;
a=b;
b=tmp;
}
int r=a%b;
while(r>0) {
a=b;
b=r;
r=a%b;
}
return b;
}
int main() {
int t;
scanf("%d",&t);
while(t--) {
int n;
int a=0,b=0;
long long sum=0;
int num[101]={0};
scanf("%d",&n);
for(int i=0; i<n; i++) {
scanf("%d",&num[i]);
}
for(int i=0; i<n-1; i++) {
a=num[i];
for(int j=i+1; j<n; j++) {
b=num[j];
sum+=gcd(a,b);
}
}
printf("%lld\n",sum);
}
return 0;
}
To embed this project on your website, copy the following code and paste it into your website's HTML: