結果

問題 No.1889 K Consecutive Ks (Hard)
ユーザー suisensuisen
提出日時 2022-03-31 16:31:02
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 373 ms / 6,000 ms
コード長 1,054 bytes
コンパイル時間 2,289 ms
コンパイル使用メモリ 116,928 KB
実行使用メモリ 15,480 KB
最終ジャッジ日時 2023-08-10 18:50:32
合計ジャッジ時間 9,185 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 367 ms
15,460 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 367 ms
15,300 KB
testcase_10 AC 361 ms
15,308 KB
testcase_11 AC 87 ms
6,636 KB
testcase_12 AC 175 ms
9,280 KB
testcase_13 AC 174 ms
9,072 KB
testcase_14 AC 174 ms
9,384 KB
testcase_15 AC 367 ms
14,928 KB
testcase_16 AC 373 ms
15,272 KB
testcase_17 AC 172 ms
9,008 KB
testcase_18 AC 364 ms
15,156 KB
testcase_19 AC 371 ms
15,480 KB
testcase_20 AC 365 ms
15,296 KB
testcase_21 AC 369 ms
15,316 KB
testcase_22 AC 361 ms
15,380 KB
testcase_23 AC 174 ms
9,828 KB
testcase_24 AC 362 ms
15,376 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);
        g = atcoder::convolution(g, h);
        res.resize(l);
        for (int i = 0; i < l; ++i) res[i] = 2 * res[i] - g[i];
    }
    return res;
}

int main() {
    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;

    auto g = atcoder::convolution(inv(f), f);
    
    std::cout << (mint(m).pow(n) - inv(f)[n]).val() << std::endl;
    return 0;
}
0