結果
問題 |
No.3089 Base M Numbers, But Only 0~9
|
ユーザー |
![]() |
提出日時 | 2025-04-04 22:37:16 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 316 ms / 2,000 ms |
コード長 | 587 bytes |
コンパイル時間 | 284 ms |
コンパイル使用メモリ | 82,320 KB |
実行使用メモリ | 76,672 KB |
最終ジャッジ日時 | 2025-04-04 22:37:23 |
合計ジャッジ時間 | 4,407 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 19 |
ソースコード
M=int(input()) N=input() p=998244353 l=len(N) all_count = 1 for i in range(len(N)-1,-1,-1): n = int(N[i]) count = (M-1-n)//10+1 if i==0 and N[i] == '0': count -= 1 all_count *= count all_count %= p if all_count == 0: print(0) exit() ans = 1 left = 1 for i in range(len(N)-1,-1,-1): n = int(N[i]) count = (M-1-n)//10+1 tmp=0 tmp += (10*(count-1))*count//2 tmp += n*count tmp%=p if i==0 and N[i] == '0': count -= 1 ans+=tmp*left*all_count*pow(count,-1,p) ans %= p left *= M left %= p print((ans-1)%p)