結果
| 問題 |
No.2193 メガの下1桁
|
| コンテスト | |
| ユーザー |
gew1fw
|
| 提出日時 | 2025-06-12 19:15:12 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,213 bytes |
| コンパイル時間 | 178 ms |
| コンパイル使用メモリ | 82,476 KB |
| 実行使用メモリ | 53,936 KB |
| 最終ジャッジ日時 | 2025-06-12 19:15:27 |
| 合計ジャッジ時間 | 2,844 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 33 WA * 7 |
ソースコード
def print_result(x, B):
if x < 10:
print(x)
else:
print('A')
M = int(input())
D = int(input())
N = int(input())
B = int(input())
x0 = M % B
# 预计算每个x的下一个状态
next_x = {}
for x in range(B):
a = (x + D) % B
if x == 0:
next_x[x] = 1 % B
else:
next_x[x] = pow(a, x, B)
memo = {}
current_x = x0
for step in range(N + 1):
if current_x in memo:
# 发现循环
first_occurrence = memo[current_x]
cycle_length = step - first_occurrence
remaining_steps = N - first_occurrence
if remaining_steps <= 0:
# 无需进入循环,直接返回当前x
break
else:
# 计算剩余步骤在循环中的位置
remainder = remaining_steps % cycle_length
final_step = first_occurrence + remainder
# 回溯到final_step
temp_x = x0
for s in range(final_step):
temp_x = next_x[temp_x]
current_x = temp_x
break
memo[current_x] = step
if step == N:
break
current_x = next_x[current_x]
# 确保current_x在B范围内
current_x %= B
print_result(current_x, B)
gew1fw