結果
問題 | No.2193 メガの下1桁 |
ユーザー |
![]() |
提出日時 | 2025-04-16 00:45:04 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,010 bytes |
コンパイル時間 | 562 ms |
コンパイル使用メモリ | 81,292 KB |
実行使用メモリ | 65,212 KB |
最終ジャッジ日時 | 2025-04-16 00:48:17 |
合計ジャッジ時間 | 2,897 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 31 WA * 7 RE * 2 |
ソースコード
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')