[파이썬 / 백준 1912번] 연속합 from sys import stdin input=stdin.readline n=int(input()) arr = list(map(int, input().split())) dp = [0] * len(arr) dp[0] = arr[0] for i in range(1, len(arr)): dp[i] = max(arr[i], dp[i-1] + arr[i]) print(max(dp)) Baekjoon Case 2021.11.26
[파이썬 / 백준 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
[파이썬 / 백준 6064번] 카잉 달력 def fm(a,b): while True: r=a%b if r==0: return b break else: a,b=b,r from sys import stdin input=stdin.readline T=int(input()) for i in range(T): M,N,x,y=map(int,input().split()) md=fm(max(M,N),min(M,N)) mx=N//md for i in range(mx+1): a=M*i+x b=a%N if b==0: b=N if b==y: print(a) break if i==mx: print(-1) Baekjoon Case 2021.11.22
[파이썬 / 백준 6588번] 골드바흐의 추측 def aristo(a): if a==1: return False else: for i in range(2, int(a**0.5)+1): if a%i==0: return False return True while True: n=int(input()) if n==0: break for i in range(3,n+1,2): if aristo(i): if aristo(n-i): print(n,'=',i,'+',n-i) break Baekjoon Case 2021.11.21
[파이썬 / 백준 1011번] Floy me to the Alpha Centauri T=int(input()) for _ in range(T): x,y=map(int,input().split()) dist=y-x #총 거리 k=1 #처음에는 1광년만 움직일 수 있음 cnt=0 #움직인 횟수 move=0 #움직인 거리 while dist>move: cnt+=1 move+=k if cnt%2==0: k+=1 print(cnt) Baekjoon Case 2021.11.18