Created
February 18, 2021 11:51
This is my code of Problem D of AtCoder Beginner Contest 180.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
x, y, a, b = [int(i) for i in input().split()] | |
exp = 0 | |
# bを足すよりもaをかけた方が経験値が稼げるパターンまで, xを増やし続ける | |
# (ある段階でbを足した方が経験値が稼げるようになると, それ以降はbを足した方が経験値が稼げる) | |
while True: | |
if x*a >= y or x*a >= x+b : | |
break | |
exp += 1 | |
x *= a | |
# 残り分はbを足す | |
exp += (y - x) // b | |
# 上の計算だとbを足し続けた結果yになる可能性もあるので, それを確認する | |
if (y-x) % b == 0: | |
exp -= 1 | |
print(exp) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment