[๋ฐฑ์ค€] 9613 GCD

cheeeeseยท2022๋…„ 5์›” 6์ผ
0

์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์—ฐ์Šต

๋ชฉ๋ก ๋ณด๊ธฐ
100/151
post-thumbnail

๐Ÿ“– ๋ฌธ์ œ

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

๐Ÿ’ป ๋‚ด ์ฝ”๋“œ

from itertools import combinations
def gcd(a,b):
    while b>0:
        a, b=b, a%b
    return a

t=int(input())
for i in range(t):
    res=0
    n, *mlist=map(int, input().split())
    cblist=list(combinations(mlist, 2))

    for k in cblist:
        res+=gcd(k[0], k[1])
                
    print(res)

๐Ÿ’ก ํ’€์ด

  • itertools์˜ combinations ์‚ฌ์šฉํ•˜์—ฌ 2๊ฐœ์˜ ์กฐํ•ฉ ๊ตฌํ•จ

0๊ฐœ์˜ ๋Œ“๊ธ€