結果
問題 | 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 % B if N == 0: final_mod = current_mod else: history = [current_mod] pos_map = {current_mod: 0} steps = 0 found_cycle = False while steps < N: steps += 1 a = (current_mod + D) % B e = current_mod if a == 0 and e == 0: new_mod = 1 % B else: new_mod = pow(a, e, B) if new_mod in pos_map: prev_step = pos_map[new_mod] cycle_length = steps - prev_step remaining = N - steps if remaining > 0: remaining_steps = remaining % cycle_length current_mod = history[prev_step + remaining_steps] steps = N # Advance steps to terminate loop else: current_mod = new_mod break else: pos_map[new_mod] = steps history.append(new_mod) current_mod = new_mod final_mod = current_mod # Convert to the last digit in base B if final_mod < 10: print(final_mod) else: print('A')