結果
| 問題 | No.3089 Base M Numbers, But Only 0~9 | 
| コンテスト | |
| ユーザー |  detteiuu | 
| 提出日時 | 2025-04-05 14:30:22 | 
| 言語 | PyPy3 (7.3.15) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 131 ms / 2,000 ms | 
| コード長 | 500 bytes | 
| コンパイル時間 | 587 ms | 
| コンパイル使用メモリ | 81,920 KB | 
| 実行使用メモリ | 76,700 KB | 
| 最終ジャッジ日時 | 2025-04-05 14:30:26 | 
| 合計ジャッジ時間 | 3,427 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 5 | 
| other | AC * 19 | 
ソースコード
M = int(input())
N = input()
def RSUM(l, r, c):
    return (l+r)*c//2
MOD = 998244353
ans = 0
C = M//10
cnt = 1
for i in range(len(N)):
    ans *= M
    ans %= MOD
    c = C
    if int(N[i]) <= M%10-1:
        c += 1
    if i == 0 and N[i] == "0":
        c -= 1
    ans *= c
    ans %= MOD
    l = int(N[i])
    diff = ((M%10-1)-int(N[i]))%10
    if i == 0 and N[i] == "0":
        l = 10
    r = M-diff-1
    ans += RSUM(l, r, c)%MOD*cnt%MOD
    ans %= MOD
    cnt *= c
    cnt %= MOD
print(ans)
            
            
            
        