어제에 이어서 문제를 풀어나갔다. 수학파트 풀이를 비교적 다른 문제에 비해서 많이 진행해서 그런지 상대적으로 큰 어려움을 느끼지는 않았다. 하지만 실수로 인해서 막히는 경우가 아직 있기에 연습이 더 필요할 것 같다. 무엇보다 꾸준히 풀어나가는 것이 중요하다고 생각한다.
백준 1676번 팩토리얼 0의 개수
from sys import stdin
N = int(stdin.readline().rstrip())
print(N//5 + N//25 + N//125)
백준 2004번 조합 0의 개수
# nCr = n!/(n-r)!r!
# 끝자리 0은 10의 배수
# 2의 개수, 5의 개수중 적은 것이 10의 개수
from sys import stdin
n,m = map(int,stdin.readline().rstrip().split())
def two(x):
count = 0
while x!=0:
x = x//2
count += x
return count
def five(x):
count = 0
while x!=0:
x = x//5
count += x
return count
print(min(two(n) - two(n - m) - two(m), five(n) - five(n - m) - five(m)))
백준 9613번 GCD 합
from sys import stdin
import math
t = int(stdin.readline())
for i in range(t):
stack = list(map(int,stdin.readline().split()))
list_num = stack.pop(0)
count = 0
for j in range(list_num):
for k in range(list_num):
if j < k:
count += math.gcd(stack[j],stack[k])
print(count)
백준 17087번 숨바꼭질 6
from sys import stdin
import math
N,S = map(int,stdin.readline().split())
A = list(map(int,stdin.readline().split()))
stack = list()
for i in A:
stack.append(abs(i-S))
for j in range(len(stack)-1):
stack[0] = math.gcd(stack[0],stack[1])
stack.pop(1)
print(stack[0])
백준 1373번 2진수 8진수
from sys import stdin
N = stdin.readline()
ten = int(N,2)
eight=str(oct(int(ten)))
print(int(eight[2:]))
백준 1212번 8진수 2진수
from sys import stdin
N = stdin.readline()
ten = int(N,8)
print(bin(int(ten))[2:])
백준 2089번 -2진수
import sys
N = int(sys.stdin.readline())
count = ''
if N==0: # 예외처리 확실히하자
print(0)
else:
while N:
if N%(-2) != 0:
count = '1' + count
N = N//-2+1
else:
count = '0' + count
N //= -2
if(N==0):
break
print(count)