結果

問題 No.2798 Multiple Chain
ユーザー aditya jain
提出日時 2024-06-28 22:29:33
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 29 ms / 2,000 ms
コード長 1,576 bytes
コンパイル時間 3,420 ms
コンパイル使用メモリ 256,556 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-06-28 22:29:47
合計ジャッジ時間 6,135 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 51
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
using namespace std;
using ll = long long int;
template<typename T>
ostream& operator+(ostream& out, const vector<T> &vec){
    for(const auto &x : vec){
        out<<x<<" ";
    }
    out<<"\n";
    return out;
}
template<typename T>
ostream& operator*(ostream& out, const vector<T> &vec){
    for(const auto &x : vec){
        out+x;
    }
    return out;
}
template<typename T>
istream& operator>>(istream& in, vector<T> &vec){
    for(auto &x : vec){
        in>>x;
    }
    return in;
}
void solve(){
    ll n;
    cin>>n;
    vector<int> pf;
    for(ll p=2;p<=2e6;p++){
        ll e = 0;
        while(n % p == 0){
            n /= p;
            ++e;
        }
        if(e > 0) pf.emplace_back(e);
    }
    
    if(n > 1){
        ll sq = sqrtl(n);
        if(sq * sq == n) pf.emplace_back(2);
        ++sq;
        if(sq * sq == n) pf.emplace_back(2);
        sq -= 2;
        if(sq * sq == n) pf.emplace_back(2);
    }

    if(pf.size() == 0){
        cout<<"1\n";
        return;
    }
    sort(pf.begin(), pf.end(), greater<int>());

    int maxL = pf[0];
    vector<vector<ll>> dp(maxL + 1, vector<ll>(maxL + 1));
    dp[0][0] = 1;
    for(int l=1;l<=maxL;l++){
        for(int s=0;s<=maxL;s++){
            for(int a=0;s-l*a>=0;a++){
                dp[l][s] += dp[l-1][s - l * a];
            }
        }
    }
    ll ans = 1;
    for(auto &e : pf){
        ans *= dp[maxL][e];
    }
    cout<<ans<<"\n";

}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
}
0