結果
問題 | No.2193 メガの下1桁 |
ユーザー |
![]() |
提出日時 | 2025-03-31 17:36:31 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,127 bytes |
コンパイル時間 | 149 ms |
コンパイル使用メモリ | 82,408 KB |
実行使用メモリ | 54,368 KB |
最終ジャッジ日時 | 2025-03-31 17:37:18 |
合計ジャッジ時間 | 2,728 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 33 WA * 7 |
ソースコード
M = int(input())D = int(input())N = int(input())B = int(input())current_mod = M % Bif N == 0:final_mod = current_modelse:history = [current_mod]pos_map = {current_mod: 0}steps = 0found_cycle = Falsewhile steps < N:steps += 1a = (current_mod + D) % Be = current_modif a == 0 and e == 0:new_mod = 1 % Belse:new_mod = pow(a, e, B)if new_mod in pos_map:prev_step = pos_map[new_mod]cycle_length = steps - prev_stepremaining = N - stepsif remaining > 0:remaining_steps = remaining % cycle_lengthcurrent_mod = history[prev_step + remaining_steps]steps = N # Advance steps to terminate loopelse:current_mod = new_modbreakelse:pos_map[new_mod] = stepshistory.append(new_mod)current_mod = new_modfinal_mod = current_mod# Convert to the last digit in base Bif final_mod < 10:print(final_mod)else:print('A')