結果
| 問題 |
No.2193 メガの下1桁
|
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 2025-04-16 00:43:53 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,137 bytes |
| コンパイル時間 | 296 ms |
| コンパイル使用メモリ | 82,148 KB |
| 実行使用メモリ | 54,176 KB |
| 最終ジャッジ日時 | 2025-04-16 00:47:47 |
| 合計ジャッジ時間 | 3,079 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 33 WA * 7 |
ソースコード
M = int(input())
D = int(input())
N = int(input())
B = int(input())
current = M % B
if N == 0:
res = current
else:
history = {current: 0}
sequence = [current]
steps = 0
found_cycle = False
while steps < N:
base = (current + D) % B
exponent = current
if base == 0:
if exponent == 0:
next_current = 1 % B
else:
next_current = 0
else:
next_current = pow(base, exponent, B)
steps += 1
if next_current in history:
cycle_start = history[next_current]
cycle_length = steps - cycle_start
remaining_steps = N - cycle_start
if remaining_steps < 0:
res = sequence[N]
else:
res = sequence[cycle_start + (remaining_steps % cycle_length)]
found_cycle = True
break
else:
history[next_current] = steps
sequence.append(next_current)
current = next_current
if not found_cycle:
res = current
if res == 10:
print('A')
else:
print(res)
lam6er