Skip to content

Instantly share code, notes, and snippets.

@uchidama
Created July 6, 2021 16:45
Show Gist options
  • Save uchidama/1fb01e8823a688411c335e7f8d364e8d to your computer and use it in GitHub Desktop.
Save uchidama/1fb01e8823a688411c335e7f8d364e8d to your computer and use it in GitHub Desktop.
AtCoder Beginner Contest 180 [ D - Takahashi Unevolved ] https://atcoder.jp/contests/abc180/tasks/abc180_d
'''
[問題]
https://atcoder.jp/contests/abc180/tasks/abc180_d
[解説]
https://youtu.be/r4ujcFBDBw4?t=2603 
 基本このsnukeさんの解説が、わかりやすい
https://atcoder.jp/contests/abc180/editorial/219
[結果]
PyPy3(7.3.0) AC 62ms
Python(3.8.2) AC 26ms
'''
import sys
sys.setrecursionlimit(10 ** 6) # 再帰上限の引き上げ
input = sys.stdin.readline
INF = 2 ** 63 - 1
X, Y, A, B = map(int, input().split())
ans = 0
# 2 <= A なので、このループは最大64回程度しか回らないので愚直にシミュレーション
while True:
if (X * A) >= Y:
break
if (X * A) < (X + B):
X *= A
ans += 1
else:
break
# +Bは単純に割り算で求められる
# 進化しないのはY-X-1の数値まで
ans += (Y-X-1)//B
print(ans)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment