結果

問題 No.3310 mod998
コンテスト
ユーザー timi
提出日時 2025-10-25 05:33:58
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 515 bytes
コンパイル時間 569 ms
コンパイル使用メモリ 82,244 KB
実行使用メモリ 78,280 KB
最終ジャッジ日時 2025-10-25 05:34:04
合計ジャッジ時間 5,992 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 3 RE * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

T=int(input())
mod=998

for _ in range(T):
  N,M=map(int, input().split())  
  D=[-1]*1000;C=[]
  now=1
  for i in range(1000):
    if D[now]==-1:
      D[now]=i
      C.append(now)
    else:
      stop=D[now]
      break 
    now=now*N%mod  
  mo=len(C);su=sum(C)%mod
  for _ in range(M):
    K=int(input())
    K+=1
    if K<=len(C):
      print(sum(C[:K])%mod)
    else:
      ans=su
      K-=len(C)
      C=C[stop:]
      su=sum(C)%mod
      ans+=(K//len(C))*su+sum(C[:K%len(C)])%mod
      print(ans%mod)
      
0