結果

問題 No.3310 mod998
コンテスト
ユーザー kidodesu
提出日時 2025-10-24 21:48:08
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 615 bytes
コンパイル時間 437 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 77,848 KB
最終ジャッジ日時 2025-10-24 21:48:30
合計ジャッジ時間 8,011 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 23 RE * 10
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 998
for _ in range(int(input())):
    n, m = map(int, input().split())
    T = []
    C = set([])
    now = 1
    while not now in C:
        C.add(now)
        T.append(now)
        now = now * n % mod
    I = {T[i]: i for i in range(len(T))}
    idx = I[now]
    B = [0]
    for t in T:
        B.append((B[-1] + t) % mod)
    for _ in range(m):
        k = int(input()) + 1
        if k < idx:
            ans = B[k]
        else:
            ans = B[idx]
            k -= idx
            s = len(T) - idx
            ans = (B[-1] - B[idx]) * (k // s) + B[k % s + idx]
        ans %= mod
        print(ans)
0