結果

問題 No.2798 Multiple Chain
ユーザー Jeroen Op de Beek
提出日時 2024-06-28 22:32:04
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 2,433 bytes
コンパイル時間 2,544 ms
コンパイル使用メモリ 206,144 KB
最終ジャッジ日時 2025-02-22 01:16:03
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 51
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
#define all(x) x.begin(),x.end()
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << p.first << " " << p.second; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { string sep; for (const T &x : v) os << sep << x, sep = " "; return os; }
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#define ASSERT(...) 42
#endif
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pi;
const int oo = 1e9;
typedef unsigned long long ull;
ull modmul(ull a, ull b, ull M) {
    ll ret = a*b - M*ull(1.L/M*a*b);
    return ret + M*(ret<0) - M*(ret>=(ll)M);

}
ull modpow(ull b, ull e, ull mod) {
    ull ans = 1;
    for(;e;b=modmul(b,b,mod),e/=2) {
        if(e&1) ans = modmul(ans,b,mod);
    }
    return ans;
}
ull pollard(ull n) {
    auto f = [n](ull x) {return modmul(x,x,n)+1;};
    ull x =0,y=0, t=30,prd=2,i=1,q;
    while(t++ %40 || gcd(prd,n)==1) {
        if(x==y) x=++i, y = f(x);
        if((q=modmul(prd,max(x,y)-min(x,y),n))) 
            prd=q;
        x = f(x),y=f(f(y));
    }
    return gcd(prd,n);
}
bool isPrime(ull n) {
    if(n<2 || n%6%4!=1) return (n|1) ==3;
    ull A[] = {2,325,9375,28178, 450775,9780504, 17952650221},
        s = __builtin_ctzll(n-1), d = n>>s;
        for(ull a : A) {
            ull p = modpow(a%n,d,n), i =s;
            while(p!=1 && p!=n-1 && a%n && i--)
                p = modmul(p,p,n);
            if(p!=n-1 && i!=s) return 0;
        }
    return 1;
}
map<ull,int> factor(ull n) {
    if(n==1 )return {};
    if(isPrime(n)) return {{n,1}};
    ull x = pollard(n);
    auto l = factor(x), r = factor(n/x);
    for(auto [i,c] : r) {
        l[i]+=c;
    }
    return l;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n; cin >> n;
    auto mp = factor(n);   
    ll ans=1;
    for(auto [k,v] : mp) {
        ll cur=0;
        auto rec = [&](auto&& self, int at, int sum, int len) {
            if(sum==v) {
                cur++;
                return;
            }
            while(at+sum<=v) {
                self(self,at,sum+at,len+1);
                at++;
            }

        };
        rec(rec,1,0,0);
        ans*=cur;
    }
    cout << ans << '\n';
}
0