結果

問題 No.2576 LCM Pattern
ユーザー otoshigootoshigo
提出日時 2023-12-06 14:42:00
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 3,395 bytes
コンパイル時間 1,219 ms
コンパイル使用メモリ 93,360 KB
実行使用メモリ 16,148 KB
最終ジャッジ日時 2023-12-06 14:42:06
合計ジャッジ時間 5,717 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
13,480 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 3 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 5 ms
6,676 KB
testcase_06 AC 148 ms
6,676 KB
testcase_07 AC 2 ms
6,676 KB
testcase_08 AC 151 ms
6,676 KB
testcase_09 AC 6 ms
6,676 KB
testcase_10 TLE -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<atcoder/modint>
using namespace std;
using namespace atcoder;
using ll=long long;
using mint=modint998244353;
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
template<class T> bool chmax(T &a, T b){if (a < b){a = b;return true;} else return false;}
template<class T> bool chmin(T &a, T b){if (a > b){a = b;return true;} else return false;}

template <class T>
struct Matrix {
    vector<vector<T>> A;
    Matrix(int n, int m) : A(n, vector<T>(m, 0)) {}
    Matrix(int n) : A(n, vector<T>(n, 0)) {}
    int height() const {
        return (A.size());
    }
    int width() const {
        return (A[0].size());
    }
    const vector<T> &operator[](int k) const {
        return (A[k]);
    }
    vector<T> &operator[](int k) {
        return (A[k]);
    }
    static Matrix I(int n) {
        Matrix mat(n);
        for (int i = 0; i < n; i++) mat[i][i] = 1;
        return mat;
    }
    Matrix &operator+=(const Matrix &B) {
        int n = height(), m = width();
        assert(n == B.height() && m == B.width());
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                (*this)[i][j] += B[i][j];
            }
        }
        return (*this);
    }
    Matrix &operator-=(const Matrix &B) {
        int n = height(), m = width();
        assert(n == B.height() && m == B.width());
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                (*this)[i][j] -= B[i][j];
            }
        }
        return (*this);
    }
    Matrix &operator*=(const Matrix &B) {
        int n = height(), m = B.width(), p = width();
        assert(p == B.height());
        vector<vector<T>> C(n, vector<T>(m, 0));
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                for (int k = 0; k < p; k++) {
                    C[i][j] += (*this)[i][k] * B[k][j];
                }
            }
        }
        A.swap(C);
        return (*this);
    }
    Matrix &operator^=(long long k) {
        int n = height();
        assert(n == width());
        Matrix B = Matrix::I(n);
        while (k > 0) {
            if (k & 1) B *= *this;
            *this *= *this;
            k >>= 1LL;
        }
        A.swap(B.A);
        return (*this);
    }
    Matrix operator+(const Matrix &B) const {
        return (Matrix(*this) += B);
    }
    Matrix operator-(const Matrix &B) const {
        return (Matrix(*this) -= B);
    }
    Matrix operator*(const Matrix &B) const {
        return (Matrix(*this) *= B);
    }
    Matrix operator^(const long long k) const {
        return (Matrix(*this) ^= k);
    }
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N,M;
    cin>>N>>M;
    vector<int>V;
    for(int x=1;x*x<=M;x++){
        if(M%x==0){
            V.push_back(x);
            if(x*x<M)V.push_back(M/x);
        }
    }
    sort(all(V));
    int L=V.size();
    Matrix<mint>mat(L);
    vector ls(L,vector<ll>(L));
    for(int i=0;i<L;i++)for(int j=0;j<L;j++)ls[i][j]=lcm(V[i],V[j]);
    for(int i=0;i<L;i++){
        for(int j=0;j<=i;j++){
            for(int k=0;k<=i;k++){
                if(ls[j][k]==V[i])mat[i][j]++;
            }
        }
    }
    mat^=N-1;
    mint ans=0;
    for(int i=0;i<L;i++)ans+=mat[L-1][i];
    cout<<ans.val()<<"\n";
}
0