Cod sursa(job #2504515)

Utilizator nikolapesic2802Nikola Pesic nikolapesic2802 Data 5 decembrie 2019 00:32:07
Problema Descompuneri Scor 16
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 2.8 kb
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ll long long
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()

using namespace std;
using namespace __gnu_pbds;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>; ///find_by_order(),order_of_key()
template<class T1, class T2> ostream& operator<<(ostream& os, const pair<T1,T2>& a) { os << '{' << a.f << ", " << a.s << '}'; return os; }
template<class T> ostream& operator<<(ostream& os, const vector<T>& a){os << '{';for(int i=0;i<sz(a);i++){if(i>0&&i<sz(a))os << ", ";os << a[i];}os<<'}';return os;}
template<class T> ostream& operator<<(ostream& os, const set<T>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
template<class T> ostream& operator<<(ostream& os, const multiset<T>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
template<class T1,class T2> ostream& operator<<(ostream& os, const map<T1,T2>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
template<class T1,class T2> ostream& operator<<(ostream& os, const gp_hash_table<T1,T2>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}

map<pair<ll,ll>,ll> dp;
vector<ll> f,divs;
vector<pair<ll,int> > d;
map<ll,vector<ll> > del;
void genAll(int tr,ll num){
    if(tr==d.size())
    {
        divs.pb(num);
        return;
    }
    for(int i=0;i<=d[tr].s;i++,num*=d[tr].f)
        genAll(tr+1,num);
}
void genDivs(ll a){
    if(del.find(a)!=del.end())
        return;
    d.clear();
    ll st=a;
    for(auto p:f){
        int cnt=0;
        while(a%p==0)
            a/=p,cnt++;
        if(cnt)
            d.pb({p,cnt});
    }
    divs.clear();
    genAll(0,1);
    sort(all(divs));
    del[st]=divs;
}
vector<ll> tr;
ll getNum(ll a,ll last){
    //printf("%lld %lld\n",a,last);
    //cout << tr << endl;
    if(a==1)
        return 1;
    if(dp.find({a,last})!=dp.end())
        return dp[{a,last}];
    genDivs(a);
    ll num=0;
    for(auto p:del[a])
        if(p>=last)
            tr.pb(p),num+=getNum(a/p,p),tr.pop_back();
    return dp[{a,last}]=num;
}
int main()
{
	freopen("desc.in","r",stdin);
	freopen("desc.out","w",stdout);
	ll n;
	int k;
	scanf("%lld %i",&n,&k);
	ll st=n;
	for(ll int i=2;i*i<=n;i++){
        if(n%i==0)
            f.pb(i);
        while(n%i==0)
            n/=i;
	}
    if(n!=1)
        f.pb(n);
    printf("%lld\n",getNum(st,2));
    return 0;
}