結果
問題 | No.3089 Base M Numbers, But Only 0~9 |
ユーザー |
![]() |
提出日時 | 2025-04-04 23:26:54 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 464 ms / 2,000 ms |
コード長 | 496 bytes |
コンパイル時間 | 175 ms |
コンパイル使用メモリ | 82,588 KB |
実行使用メモリ | 95,060 KB |
最終ジャッジ日時 | 2025-04-04 23:27:02 |
合計ジャッジ時間 | 7,796 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge6 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 19 |
ソースコード
M=998244353 m=int(input()) n=list(map(int,input()))[::-1] l=len(n) pl=[1]*(l+1) for i in range(l): d=n[i] c=(m-1-d)//10+1-(i==l-1 and d==0) pl[i+1]=pl[i]*c%M pr=[1]*(l+1) for i in range(l): d=n[~i] c=(m-1-d)//10+1-(i==0 and d==0) pr[i+1]=pr[i]*c%M a=0 for i in range(l): d=n[i] c=(m-1-d)//10+1 if i==l-1 and d==0: c-=1 a+=(((c+1)*c*pow(2,M-2,M))*10+d*c)*pl[i]*pr[l-i-1]*pow(m,i,M) else: a+=(((c-1)*c*pow(2,M-2,M))*10+d*c)*pl[i]*pr[l-i-1]*pow(m,i,M) a%=M print(a)