結果

問題 No.2487 Multiple of M
ユーザー 259-Momone259-Momone
提出日時 2023-09-29 22:04:26
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,536 bytes
コンパイル時間 2,794 ms
コンパイル使用メモリ 267,684 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-30 12:51:05
合計ジャッジ時間 4,661 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
testcase_52 WA -
testcase_53 WA -
testcase_54 WA -
testcase_55 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

// #include <atcoder/modint>
#include <bits/extc++.h>

int main() {
    using namespace std;
    // using modint = atcoder::static_modint<998244353>;
    unsigned long N, M, K;
    cin >> N >> M >> K;
    auto g{gcd(M, K)};
    vector<unsigned long> prime_factors;
    for (unsigned long p{2}; p * p <= g; ++p)
        if (g % p == 0) {
            prime_factors.emplace_back(p);
            while (g % p == 0)
                g /= p;
        }
    if(g > 1)prime_factors.emplace_back(g);
    
    const auto P{size(prime_factors)};
    auto M_p{M};
    vector<unsigned long> counter(60, 1);
    for (unsigned long i{}; i < P; ++i) {
        const auto p{prime_factors[i]};
        unsigned long x_M{1}, x_K{1};
        while (M_p % p == 0) {
            M_p /= p;
            x_M *= p;
        }
        while (K % (x_K * p) == 0)
            x_K *= p;
        unsigned long x{1};
        for (unsigned long j{}; j < 60; ++j) {
            counter[j] *= x;
            x = min(x_M, x * x_K);
        }
    }

    for (unsigned long j{60}; --j;)
        counter[j] -= counter[j - 1];

    while (counter.back() == 0)
        counter.pop_back();

    counter.emplace_back(M / M_p * (M_p - 1));

    for (const auto c : counter)
        cout << c << " ";
    cout << endl;

    const auto C{size(counter)};

    vector matrix(C, vector<unsigned long>(C));
    for (unsigned long i{}; i < C; ++i) {
        for (unsigned long j{}; j < C; ++j)
            matrix[i][j] = counter[j];
        matrix[i][i - (i && i + 1 < C)] -= 1;
    }

    for (const auto &row : matrix) {
        for (const auto c : row)
            cout << c << " ";
        cout << endl;
    }
    cout << endl;

    vector ans(C, vector<unsigned long>(C));
    for (unsigned long i{}; i < C; ++i)
        ans[i][i] = 1;

    const auto multiply{
        [C](const auto &lhs, const auto &rhs) {
            vector ret(C, vector<unsigned long>(C));
            for (unsigned long i{}; i < C; ++i) {
                for (unsigned long j{}; j < C; ++j) {
                    for (unsigned long k{}; k < C; ++k) {
                        ret[i][k] += lhs[i][j] * rhs[j][k] % 998244353;
                    }
                }
            }
            for (auto &&row : ret)
                for (auto &&x : row)
                    x %= 998244353;
            return ret;
        }};

    while (N) {
        if (N & 1)
            ans = multiply(ans, matrix);
        matrix = multiply(matrix, matrix);
        N /= 2;
    }

    cout << ans[0][0] << endl;
    return 0;
}
0