BOJ - 9613 - GCD 합

Updated:

import sys
import itertools

def GCD(a, b):
    return GCD(b, a % b) if b else a

def solution():
    T = int(input())
    
    for i in range(T):
        numlist = list(map(int, sys.stdin.readline().split()))
        numlist = numlist[1:]
        
        ret = 0
        
        for a, b in itertools.combinations(numlist, 2):

            ret += GCD(a, b)
        print(ret)
solution()

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

Categories:

Updated:

Leave a comment