結果

問題 No.2060 AND Sequence
ユーザー 👑 tamatotamato
提出日時 2022-08-26 21:53:29
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 79 ms / 2,000 ms
コード長 1,054 bytes
コンパイル時間 344 ms
コンパイル使用メモリ 86,792 KB
実行使用メモリ 71,524 KB
最終ジャッジ日時 2023-08-04 01:22:28
合計ジャッジ時間 5,900 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
71,388 KB
testcase_01 AC 76 ms
71,136 KB
testcase_02 AC 79 ms
71,072 KB
testcase_03 AC 74 ms
71,068 KB
testcase_04 AC 76 ms
71,392 KB
testcase_05 AC 73 ms
71,188 KB
testcase_06 AC 74 ms
71,200 KB
testcase_07 AC 74 ms
71,196 KB
testcase_08 AC 74 ms
71,264 KB
testcase_09 AC 73 ms
71,188 KB
testcase_10 AC 75 ms
71,196 KB
testcase_11 AC 75 ms
71,184 KB
testcase_12 AC 73 ms
71,352 KB
testcase_13 AC 73 ms
71,132 KB
testcase_14 AC 75 ms
71,340 KB
testcase_15 AC 74 ms
71,368 KB
testcase_16 AC 75 ms
71,196 KB
testcase_17 AC 76 ms
71,024 KB
testcase_18 AC 76 ms
71,208 KB
testcase_19 AC 75 ms
71,184 KB
testcase_20 AC 76 ms
71,128 KB
testcase_21 AC 74 ms
71,036 KB
testcase_22 AC 76 ms
71,288 KB
testcase_23 AC 76 ms
71,244 KB
testcase_24 AC 75 ms
71,388 KB
testcase_25 AC 75 ms
71,204 KB
testcase_26 AC 75 ms
71,136 KB
testcase_27 AC 75 ms
71,204 KB
testcase_28 AC 76 ms
71,176 KB
testcase_29 AC 75 ms
71,464 KB
testcase_30 AC 75 ms
71,176 KB
testcase_31 AC 77 ms
71,392 KB
testcase_32 AC 75 ms
71,200 KB
testcase_33 AC 75 ms
71,384 KB
testcase_34 AC 75 ms
71,196 KB
testcase_35 AC 76 ms
71,200 KB
testcase_36 AC 76 ms
71,340 KB
testcase_37 AC 74 ms
71,524 KB
testcase_38 AC 76 ms
71,352 KB
testcase_39 AC 73 ms
71,264 KB
testcase_40 AC 75 ms
71,412 KB
testcase_41 AC 77 ms
71,392 KB
testcase_42 AC 75 ms
71,080 KB
testcase_43 AC 76 ms
71,388 KB
testcase_44 AC 75 ms
71,044 KB
testcase_45 AC 75 ms
71,308 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 998244353


def main():
    import sys
    input = sys.stdin.readline

    # comb init
    nmax = 30 + 10  # change here
    fac = [0] * nmax
    finv = [0] * nmax
    inv = [0] * nmax
    fac[0] = 1
    fac[1] = 1
    finv[0] = 1
    finv[1] = 1
    inv[1] = 1
    for i in range(2, nmax):
        fac[i] = fac[i - 1] * i % mod
        inv[i] = mod - inv[mod % i] * (mod // i) % mod
        finv[i] = finv[i - 1] * inv[i] % mod

    def comb(n, r):
        if n < r:
            return 0
        else:
            return (fac[n] * ((finv[r] * finv[n - r]) % mod)) % mod

    N, M = map(int, input().split())

    popcnt = [0] * 31
    cnt1 = 0
    for i in range(M.bit_length() - 1, -1, -1):
        if M >> i & 1:
            K = i
            for k in range(K + 1):
                popcnt[k + cnt1] = (popcnt[k + cnt1] + comb(K, k)) % mod
            cnt1 += 1
    popcnt[cnt1] += 1
    ans = 0
    for i in range(31):
        tmp = pow(N, i, mod)
        ans = (ans + tmp * popcnt[i])%mod
    print(ans)


if __name__ == '__main__':
    main()
0