結果

問題 No.3089 Base M Numbers, But Only 0~9
ユーザー PNJ
提出日時 2025-04-04 21:53:27
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 50 ms / 2,000 ms
コード長 539 bytes
コンパイル時間 366 ms
コンパイル使用メモリ 82,188 KB
実行使用メモリ 69,192 KB
最終ジャッジ日時 2025-04-04 21:53:56
合計ジャッジ時間 2,409 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 998244353
M = int(input())
C = [0 for _ in range(10)]
S = [0 for _ in range(10)]

for c in range(10):
  r = M % 10
  n = (M // 10)
  if r > c:
    n += 1
  n %= mod
  C[c] = n % mod
  S[c] = n * c + 5 * (n * (n - 1) % mod)
  S[c] %= mod

N = input()
if N[0] == '0' and M == 10:
  print(0)
  exit()

ans = 0
res = 1
M %= mod
for i in range(len(N)):
  ans = ans * M % mod
  n = int(N[i])
  c = C[n]
  if n == 0 and i == 0:
    c -= 1
    c %= mod
  ans = ans * c % mod
  ans = (ans + S[n] * res) % mod
  res = res * c % mod
print(ans)
0