Skip to main content

9613. GCD 합

·86 words·1 min· loading

https://www.acmicpc.net/problem/9613

9613번: GCD 합첫째 줄에 테스트 케이스의 개수 t (1 ≤ t ≤ 100)이 주어진다. 각 테스트 케이스는 한 줄로 이루어져 있다. 각 테스트 케이스는 수의 개수 n (1 < n ≤ 100)가 주어지고, 다음에는 n개의 수가 주어진www.acmicpc.net

진짜 쉬운 문제인데 각 줄의 첫번째가 n이라는걸 간과해서 시간을 오래 잡아먹었다.

배열에 2가지를 넣는 경우의 수를 구하고, 이의 최소공배수를 각각 구한다.

from itertools import combinationsdef gcd(a,b):    while True:        a,b=b,a%b
        if b==0: return a        t=int(input())for _ in range(t):
    l=list(map(int,input().split()))    n=l.pop(0)      answer=0    
    com=combinations(l,2)    for i in com:        a,b=i        answer+=gcd(a,b)
    print(answer)