結果

問題 No.2318 Phys Bone Maker
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2023-05-26 23:00:16
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
AC  
実行時間 2,448 ms / 3,000 ms
コード長 3,244 bytes
コンパイル時間 1,566 ms
コンパイル使用メモリ 132,200 KB
実行使用メモリ 24,448 KB
最終ジャッジ日時 2024-12-25 10:04:07
合計ジャッジ時間 18,405 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 45
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <numeric>
#include <deque>

using namespace std;
using ll = long long;

map<ll, ll> prime;
vector<ll> factor;

void prime_factor(ll n){
    ll m = n;

    if (n % 2 == 0){
        while(n % 2 == 0){
            prime[2]++;
            n /= 2;
        }
    }

    for (ll i = 3; i*i <= m; i+=2){
        if (n % i == 0){
            while(n % i == 0){
                prime[i]++;
                n /= i;
            }
        }
    }

    if (n != 1){
        prime[n]++;
    }
}

void all_factor(ll n){
    for (ll i = 1; i*i <= n; i++){
        if (n % i == 0){
            factor.push_back(i);
            if (i*i != n) factor.push_back(n / i);
        }
    }
    sort(factor.begin(), factor.end());
}


const ll modc = 998244353;
class mint {
    ll x;
public:
    mint(ll x=0) : x((x%modc+modc)%modc) {}
    mint operator-() const {
      return mint(-x);
    }
    mint& operator+=(const mint& a) {
        if ((x += a.x) >= modc) x -= modc;
        return *this;
    }
    mint& operator-=(const mint& a) {
        if ((x += modc-a.x) >= modc) x -= modc;
        return *this;
    }
    mint& operator*=(const  mint& a) {
        (x *= a.x) %= modc;
        return *this;
    }
    mint operator+(const mint& a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint& a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint& a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    mint inv() const {
        return pow(modc-2);
    }
    mint& operator/=(const mint& a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint& a) const {
        mint res(*this);
        return res/=a;
    }
    bool operator == (const mint& a) const{
        return x == a.x;
    }
    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.x;
        return os;
    }
    friend istream& operator>>(istream& ip, mint&m) {
        ip >> m.x;
        return ip;
    }
};

ll N, M;
map<ll, vector<ll>> e, p;

map<ll, mint> mp;

mint solve(ll X){
    if (X == 1) return 1;
    if (mp.count(X)) return mp[X];
    mint res = 0, cnt;
    for (auto y : p[X]){
        cnt = 1;
        for (int i=0; i<M; i++){
            if (e[y][i] == e[X][i]) cnt *= (e[X][i]+1);
        }
        res += cnt * solve(y);
    }
    return mp[X] = res;
}

int main(){

    cin >> N;
    prime_factor(N);
    all_factor(N);
    M = prime.size();

    for (auto x : factor){
        vector<ll> v(M);
        ll cnt=0, a=x;
        for (auto [y, z] : prime){
            ll num=0;
            while(a % y == 0){
                a /= y;
                num++;
            }
            v[cnt] = num;
            cnt++;
        }
        e[x] = v;
    }

    for (auto x : factor){
        for (auto y : factor){
            if (y == x) break;
            if (x % y == 0) p[x].push_back(y);
        }
    }

    cout << solve(N) << endl;

    return 0;
}
0