結果

問題 No.2318 Phys Bone Maker
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2023-05-26 23:00:16
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2,585 ms / 3,000 ms
コード長 3,244 bytes
コンパイル時間 1,530 ms
コンパイル使用メモリ 132,112 KB
実行使用メモリ 24,408 KB
最終ジャッジ日時 2023-08-26 13:22:41
合計ジャッジ時間 18,993 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2,585 ms
24,408 KB
testcase_03 AC 9 ms
4,380 KB
testcase_04 AC 12 ms
4,380 KB
testcase_05 AC 11 ms
4,376 KB
testcase_06 AC 11 ms
4,380 KB
testcase_07 AC 3 ms
4,376 KB
testcase_08 AC 11 ms
4,376 KB
testcase_09 AC 9 ms
4,376 KB
testcase_10 AC 17 ms
4,380 KB
testcase_11 AC 12 ms
4,376 KB
testcase_12 AC 17 ms
4,380 KB
testcase_13 AC 17 ms
4,376 KB
testcase_14 AC 13 ms
4,376 KB
testcase_15 AC 11 ms
4,376 KB
testcase_16 AC 11 ms
4,376 KB
testcase_17 AC 16 ms
4,380 KB
testcase_18 AC 16 ms
4,376 KB
testcase_19 AC 7 ms
4,376 KB
testcase_20 AC 13 ms
4,380 KB
testcase_21 AC 11 ms
4,380 KB
testcase_22 AC 10 ms
4,376 KB
testcase_23 AC 10 ms
4,380 KB
testcase_24 AC 15 ms
4,380 KB
testcase_25 AC 13 ms
4,380 KB
testcase_26 AC 13 ms
4,376 KB
testcase_27 AC 15 ms
4,376 KB
testcase_28 AC 9 ms
4,380 KB
testcase_29 AC 9 ms
4,376 KB
testcase_30 AC 7 ms
4,376 KB
testcase_31 AC 17 ms
4,376 KB
testcase_32 AC 15 ms
4,376 KB
testcase_33 AC 2 ms
4,380 KB
testcase_34 AC 13 ms
4,376 KB
testcase_35 AC 194 ms
5,720 KB
testcase_36 AC 887 ms
13,276 KB
testcase_37 AC 1,055 ms
14,316 KB
testcase_38 AC 1,077 ms
15,644 KB
testcase_39 AC 1,442 ms
17,880 KB
testcase_40 AC 1,655 ms
19,236 KB
testcase_41 AC 1,745 ms
19,448 KB
testcase_42 AC 2,018 ms
21,240 KB
testcase_43 AC 20 ms
4,380 KB
testcase_44 AC 286 ms
8,568 KB
testcase_45 AC 268 ms
8,084 KB
testcase_46 AC 2,119 ms
23,732 KB
testcase_47 AC 18 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

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