結果
問題 |
No.3118 Increment or Multiply
|
ユーザー |
![]() |
提出日時 | 2025-04-20 03:14:01 |
言語 | PyPy3 (7.3.15) |
結果 |
MLE
|
実行時間 | - |
コード長 | 905 bytes |
コンパイル時間 | 456 ms |
コンパイル使用メモリ | 82,836 KB |
実行使用メモリ | 848,736 KB |
最終ジャッジ日時 | 2025-04-20 03:14:09 |
合計ジャッジ時間 | 6,492 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | -- * 1 |
other | MLE * 1 -- * 34 |
ソースコード
import sys input = sys.stdin.readline mod=998244353 def calc(N,A): DP=[1<<60]*(N+1) DP[N]=0 for i in range(N,-1,-1): if i%A==0: DP[i//A]=min(DP[i//A],DP[i]+1) if i-1>=0: DP[i-1]=min(DP[i-1],DP[i]+1) return DP T=int(input()) for tests in range(T): N,A=map(int,input().split()) LIST=[(N,0)] now=N kai=0 while now>1: k=now%A LIST.append(((now-k)//A,kai+k+1)) now=(now-k)//A kai+=k+1 ANS=0 #print(LIST) for i in range(len(LIST)): if i<len(LIST)-1: a,b=LIST[i] c,d=LIST[i+1] ANS+=(b+(b+(a-c-1)))*(a-c)//2 ANS%=mod #print(ANS) else: a,b=LIST[i] if a==1: ANS+=b else: pass print(ANS%mod)