Skip to content

Instantly share code, notes, and snippets.

@Shinoryo
Created February 18, 2021 11:51
This is my code of Problem D of AtCoder Beginner Contest 180.
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