코딩/공부

[Python] 백준 2914번 - 저작권

취미니스트 2023. 10. 10. 15:25
728x90
반응형

문제

https://www.acmicpc.net/problem/2914

 

올림을 계산하기 위해 math 모듈의 ceil 함수를 불러옴

from math import ceil

두 정수를 입력받고 최대 멜로디 수를 계산

a, i = list(map(int, input().split()))
m = a * i

i 값이 입력받은 값보다 작아질때까지 m의 값을 1씩 낮춰가며 비교

while True:
    temp = ceil(m / a)
    if temp < i:
        break
    m -= 1

m 값에 1을 더해 출력 (이전에 빼주었기 때문에)

print(m + 1)

전체 코드

from math import ceil


a, i = list(map(int, input().split()))
m = a * i
while True:
    temp = ceil(m / a)
    if temp < i:
        break
    m -= 1
print(m + 1)
728x90
반응형