結果

問題 No.2193 メガの下1桁
ユーザー lam6er
提出日時 2025-04-16 00:48:31
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,010 bytes
コンパイル時間 145 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 67,416 KB
最終ジャッジ日時 2025-04-16 00:51:23
合計ジャッジ時間 2,377 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 31 WA * 7 RE * 2
権限があれば一括ダウンロードができます

ソースコード

diff #

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

D_mod = D % B
current = M % B

if N == 0:
    res = current
else:
    history = [current]
    seen = {current: 0}
    found_cycle = False
    ans = current

    for step in range(1, N + 1):
        a = (current + D_mod) % B
        e = current
        if a == 0 and e == 0:
            next_x = 1 % B
        else:
            next_x = pow(a, e, B)
        
        if next_x in seen:
            cycle_start = seen[next_x]
            cycle_length = step - cycle_start
            remaining = N - step
            pos = cycle_start + (remaining % cycle_length)
            ans = history[pos]
            found_cycle = True
            break
        
        seen[next_x] = step
        history.append(next_x)
        current = next_x
        
        if step == N:
            ans = current
            found_cycle = True
            break
    
    if not found_cycle:
        ans = current

if ans < 10:
    print(ans)
else:
    print('A')
0