結果

問題 No.3089 Base M Numbers, But Only 0~9
ユーザー 学ぶマン
提出日時 2025-04-04 23:20:34
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 3,450 bytes
コンパイル時間 386 ms
コンパイル使用メモリ 82,768 KB
実行使用メモリ 105,664 KB
最終ジャッジ日時 2025-04-04 23:20:42
合計ジャッジ時間 6,474 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 13 WA * 6
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys, math
sys.setrecursionlimit(10**8)
sys.set_int_max_str_digits(0)
INF = 10**18
MOD = 998244353
from bisect import bisect_left, bisect_right
from collections import deque, defaultdict, Counter
from itertools import product, combinations, permutations, groupby, accumulate
from heapq import heapify, heappop, heappush
def I():   return sys.stdin.readline().rstrip()
def II():  return int(sys.stdin.readline().rstrip())
def IS():  return sys.stdin.readline().rstrip().split()
def MII(): return map(int, sys.stdin.readline().rstrip().split())
def LI():  return list(sys.stdin.readline().rstrip())
def TII(): return tuple(map(int, sys.stdin.readline().rstrip().split()))
def LII(): return list(map(int, sys.stdin.readline().rstrip().split()))
def LSI(): return list(map(str, sys.stdin.readline().rstrip().split()))
def GMI(): return list(map(lambda x: int(x) - 1, sys.stdin.readline().rstrip().split()))
def kiriage(a, b): return (a+b-1)//b
#def check(i:int, j:int): return 0 <= i < H and 0 <= j < W

class Modint(int):
    mod = 998244353
    
    def modpow(self, i: int, r: int) -> int:
        return pow(i, r, Modint.mod)

    def modinv(self, i: int, r: int = 1) -> int:
        return pow(i, Modint.mod - 1 - r, Modint.mod)

    def __add__(self, other):
        return Modint(int.__add__(self, other) % Modint.mod)

    def __sub__(self, other):
        return Modint(int.__sub__(self, other) % Modint.mod)

    def __mul__(self, other):
        return Modint(int.__mul__(self, other) % Modint.mod)

    def __floordiv__(self, other):
        return Modint(int.__mul__(self, self.modinv(other)) % Modint.mod)

    __truediv__ = __floordiv__

    def __pow__(self, other):
        return Modint(self.modpow(self, other))

    def __radd__(self, other):
        return Modint(int.__add__(other, self) % Modint.mod)

    def __rsub__(self, other):
        return Modint(int.__sub__(other, self) % Modint.mod)

    def __rmul__(self, other):
        return Modint(int.__mul__(other, self) % Modint.mod)

    def __rfloordiv__(self, other):
        return Modint(int.__mul__(other, self.modinv(self)) % Modint.mod)

    __rtruediv__ = __rfloordiv__

    def __rpow__(self, other):
        return Modint(self.modpow(other, self))

    def __iadd__(self, other):
        self = self.__add__(other)
        return self

    def __isub__(self, other):
        self = self.__sub__(other)
        return self

    def __imul__(self, other):
        self = self.__mul__(other)
        return self

    def __ifloordiv__(self, other):
        self = self.__mul__(self.modinv(other))
        return self

    def __neg__(self):
        return (self.mod - self) % self.mod

    __itruediv__ = __ifloordiv__

    def __ipow__(self, other):
        self = Modint(self.modpow(self, other))
        return self

def tousa_sum(a, d, n):
    res = ((2*a + (n - 1)*d)*n)//2
    return res%MOD

M = II()
N = I()
lenN = len(N)

soseki = Modint(1)
cnts = []
N2 = []
for num in N:
    num = int(num)
    N2.append(num)
    cnt = 1 + ((M - 1 - num)//10)
    soseki *= cnt
    cnts.append(cnt)

limit = 2*10**5
power_M = [1]
for i in range(limit):
    power_M.append((power_M[-1]*M)%MOD)

ans = Modint(0)
for i in range(lenN):
    keta = lenN - 1 - i
    num, cnt = N2[i], cnts[i]
    sub = Modint(0)
    sub += tousa_sum(num, 10, cnt)
    sub *= soseki
    sub /= cnt
    # M の累乗を掛ける(Mの keta乗)
    sub *= power_M[keta]
    ans += sub

print(ans)
0