9417번

· 백준
코드#include #include #include #include using namespace std;int n;string s;// 유클리드 호제법, 최대공약수 구하기int gcd(int x, int y) { while (y) { int tmp = x; x = y; y = tmp % y; } return x;}// 문자열 파싱vector split(string s, string sp) { vector v; long long idx = -1; while ((idx = s.find(sp)) != string::npos) { string tmp = s.substr(0, idx); v.push_back(tmp); s.erase(0, idx + sp.length()); } v.push_back(s)..
· 백준
코드 1 (itertools, math 모듈 사용) from itertools import combinations from math import gcd tc = int(input()) for _ in range(tc): list = [*map(int,input().split())] res = 0 for i in combinations(list,2): res = max(res, gcd(*i)) print(res) 코드 2 (모듈 사용 X) def gcd(a,b): # 유클리드 호제법 while b: a,b = b, a%b return a tc = int(input()) for _ in range(tc): list = [*map(int,input().split())] res = 0 for i in range..