結果

問題 No.1889 K Consecutive Ks (Hard)
ユーザー suisensuisen
提出日時 2022-03-31 16:34:34
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 179 ms / 6,000 ms
コード長 1,099 bytes
コンパイル時間 2,411 ms
コンパイル使用メモリ 117,112 KB
実行使用メモリ 13,792 KB
最終ジャッジ日時 2024-04-28 12:18:07
合計ジャッジ時間 5,587 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 177 ms
13,784 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 3 ms
5,376 KB
testcase_09 AC 175 ms
13,628 KB
testcase_10 AC 177 ms
13,784 KB
testcase_11 AC 42 ms
5,816 KB
testcase_12 AC 86 ms
8,412 KB
testcase_13 AC 85 ms
8,200 KB
testcase_14 AC 86 ms
8,564 KB
testcase_15 AC 177 ms
12,936 KB
testcase_16 AC 177 ms
13,632 KB
testcase_17 AC 83 ms
8,144 KB
testcase_18 AC 177 ms
13,464 KB
testcase_19 AC 178 ms
13,512 KB
testcase_20 AC 179 ms
13,656 KB
testcase_21 AC 178 ms
13,792 KB
testcase_22 AC 178 ms
13,792 KB
testcase_23 AC 87 ms
8,744 KB
testcase_24 AC 178 ms
13,660 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>

#include <atcoder/modint>
#include <atcoder/convolution>

using mint = atcoder::modint998244353;

std::vector<mint> inv(const std::vector<mint> &f) {
    const int n = f.size();
    std::vector<mint> res { f[0].inv() };
    for (int k = 1; k < n; k *= 2) {
        const int l = std::min(2 * k + 1, n);
        std::vector<mint> g(f.begin(), f.begin() + l);
        std::vector<mint> h = atcoder::convolution(res, res);
        h.resize(l);
        g = atcoder::convolution(g, h);
        res.resize(l);
        for (int i = 0; i < l; ++i) res[i] = res[i] + res[i] - g[i];
    }
    return res;
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);

    int n, m;
    std::cin >> n >> m;

    std::vector<mint> f(n + 1);
    // Σ[i=1,m] (1-x^i)^(-1) mod x^(n+1)
    for (int i = 1; i <= m; ++i) for (int j = 0; i * j <= n; ++j) {
        ++f[i * j];
    }
    // f *= 1 - x
    for (int i = n - 1; i >= 0; --i) {
        f[i + 1] -= f[i];
    }
    f[0] += 1 - m;
    
    std::cout << (mint(m).pow(n) - inv(f)[n]).val() << std::endl;
    return 0;
}
0