728x90

Baekjoon Case 69

[파이썬 / 백준 9613번] GCD 합

Combination 함수로 조합을 구한다음에 그 조합의 공약수를 더하면 끗! from itertools import combinations from sys import stdin def ul(a,b): while True: r=a%b if r==0: return b break else: a,b=b,r input=stdin.readline N=int(input()) for _ in range(N): NL=list(map(int,input().split())) n=NL[0] del NL[0] SL=list(combinations(NL,2)) ans=0 for i in range(len(SL)): x=max(SL[i][0],SL[i][1]) y=min(SL[i][1],SL[i][0]) ans+=ul(x,y)..

Baekjoon Case 2021.11.24

[파이썬 / 백준 2004번] 조합 0의 개수

진짜.. 나는 바보다 인증 한 문제 노트에 먼저 조합 개수 구할때는 굳이 다 곱하지 않고 약분해서 구해놓고 코딩 짤 때는 팩토리얼 수를 다 구해서 나누려고 하다니... 그것도 모자라서 동적계획법으로 하려고 이리저리 애쓰다가 결국 검색을 했다. ㄸㅣ용.. 노트에 구현 방법을 다 써놓고도 생각 못하는 나란 바보.. 나는 바보.. 어쨌든 아래와 같이 풀이하면 된다. n,m=map(int,input().split()) c=n-m def two(x): cnt=0 while x!=0: x=x//2 cnt+=x return cnt def five(x): cnt=0 while x!=0: x=x//5 cnt+=x return cnt n2,n5=two(n),five(n) m2,m5=two(m),five(m) c2,c5=t..

Baekjoon Case 2021.11.23
728x90