Skip to content

Latest commit

 

History

History

20_9613

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
file name src tags done draft level difficulty date
9613.py
GCD 합
유클리드 호제법
수학
정수론
true
false
8
Silver III
2021-11-02

GCD 합

정답 코드

import sys

def input(): return sys.stdin.readline().rstrip()

def GCD(a, b):
    while b:
        a, b = b, a % b
    return a

for _ in range(int(input())):

    # 가장 앞 원소는 생략한다.
    nums = list(map(int, input().split()[1:]))

    nums_count = len(nums)

    answer = 0

    # combination
    for i in range(nums_count):
        for j in range(i+1, nums_count):
            answer += GCD(nums[i], nums[j])

    print(answer)