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
반응형
'코딩 > 공부' 카테고리의 다른 글
[Python] 백준 2675번 - 문자열 반복 (1) | 2023.10.10 |
---|---|
[Python] 백준 5355번 - 화성 수학 (1) | 2023.10.10 |
[Python] 백준 2530번 - 인공지능 시계 (2) | 2023.10.10 |
[Python] 백준 2525번 - 오븐 시계 (0) | 2023.10.10 |
[Python] 백준 10699번 - 오늘 날짜 (0) | 2023.10.10 |