結果
問題 | No.2193 メガの下1桁 |
ユーザー |
![]() |
提出日時 | 2025-06-12 19:21:40 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,338 bytes |
コンパイル時間 | 166 ms |
コンパイル使用メモリ | 82,568 KB |
実行使用メモリ | 54,300 KB |
最終ジャッジ日時 | 2025-06-12 19:22:05 |
合計ジャッジ時間 | 2,658 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 33 WA * 7 |
ソースコード
def find_cycle(m0, D_mod, B): seen = {} path = [] current = m0 step = 0 while current not in seen: seen[current] = step path.append(current) base = (current + D_mod) % B exponent = current if base == 0 and exponent == 0: next_m = 1 % B else: next_m = pow(base, exponent, B) current = next_m step += 1 cycle_start = seen[current] cycle_length = step - cycle_start # Generate the loop elements loop = [] if cycle_length > 0: loop.append(current) for _ in range(cycle_length - 1): base = (loop[-1] + D_mod) % B exponent = loop[-1] if base == 0 and exponent == 0: next_m = 1 % B else: next_m = pow(base, exponent, B) loop.append(next_m) return path, cycle_start, cycle_length, loop # Read input M = int(input()) D = int(input()) N = int(input()) B = int(input()) D_mod = D % B initial_m = M % B path, cycle_start, cycle_length, loop = find_cycle(initial_m, D_mod, B) if N < len(path): final_m = path[N] else: remaining = N - cycle_start index = remaining % cycle_length final_m = loop[index] # Convert to B-based last digit if final_m < 10: print(final_m) else: print('A')