1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | #include<cstdio> int arr[101]; int gcd(int a, int b) { if (b==0) return a; else return gcd(b,a%b); } int main(void) { int t,temp; long long g; scanf("%d", &t); while(t--) { scanf("%d", &temp); arr[0]={0}; for(int i=0; i<temp; i++) scanf(" %d", &arr[i]); g=0; for(int i=0; i<temp-1; i++) { for(int j=i+1; j<temp; j++) g+=gcd(arr[i],arr[j]); } printf("%lld\n", g); } return 0; } | cs |
'백준 1 > 수학' 카테고리의 다른 글
| [백준 11005] 진법 변환 2 (0) | 2020.12.06 |
|---|---|
| [백준 2745] 진법 변환 (0) | 2020.12.05 |
| [백준 1934] 최소공배수 (0) | 2020.12.05 |
| [백준 2609] 최대공약수와 최소공배수 (0) | 2020.12.05 |
| [백준 2751] 수 정렬하기 2 (0) | 2020.12.05 |