結果

問題 No.2193 メガの下1桁
ユーザー gew1fw
提出日時 2025-06-12 14:22:45
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 585 bytes
コンパイル時間 569 ms
コンパイル使用メモリ 82,344 KB
実行使用メモリ 67,616 KB
最終ジャッジ日時 2025-06-12 14:22:51
合計ジャッジ時間 6,108 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 29 WA * 6 TLE * 1 -- * 4
権限があれば一括ダウンロードができます

ソースコード

diff #

M = int(input())
D = int(input())
N = int(input())
B = int(input())

current = M % B
steps = 0
prev = None

while steps < N:
    if current == prev:
        # Convergence detected, break the loop
        break
    prev = current
    a = (current + D) % B
    e = current
    if a == 0:
        if e == 0:
            current = 1 % B
        else:
            current = 0
    else:
        if e == 0:
            current = 1 % B
        else:
            current = pow(a, e, B)
    steps += 1

# Determine the last digit in base B
digit = current % B
print(digit if digit < 10 else 'A')
0