174292025-07-16 01:02:11peti1234Sixcpp17Accepted 100/100418ms756 KiB
#include <bits/stdc++.h>

using namespace std;
const int mod=1e9+7;
int n;
vector<int> hatv; // -1: nem volt meg, 0-i: a komponenseben a legkisebb, i+1 - mar ketszer volt
long long val;
void oszt(long long a) {
    if (val%a==0) {
        int cnt=0;
        while (val%a==0) val/=a, cnt++;
        hatv.push_back(cnt);
    }
}
map<vector<int>, long long> m;
long long solve(vector<int> sor) {
    if (m[sor]) {
        return m[sor];
    }
    long long ans=1;
    for (int mask=1; mask<(1<<n); mask++) { // mask=0 nem lehet
        int opt=1; // hany lehetoseg van
        bool jo=1; // szabalyos lepes?
        int ert=-1;
        for (int i=0; i<n; i++) {
            if (mask & (1<<i)) {
                opt=opt*hatv[i];
                if (sor[i]>i) jo=0;
                if (sor[i]!=-1) {
                    if (ert==-1) ert=sor[i];
                    else if (ert!=sor[i]) jo=0;
                }
            }
        }
        if (!jo) continue; // szabalytalan volt nem kell szamolni


        vector<int> kov=sor; // mi lesz a kovetkezo vektor

        int cel=0, cel2=0; // az uj komponens cel-ba, a regi cel2-be fog menni
        for (int i=0; i<n; i++) {
            if ((mask & (1<<i)) && sor[i]==-1) {
                cel=i;
                break;
            }
        }
        for (int i=0; i<n; i++) {
            if ((mask & (1<<i))==0 && sor[i]==ert && i>=ert) {
                cel2=i;
                break;
            }
        }

        for (int i=0; i<n; i++) {
            if ((mask & (1<<i)) && kov[i]!=-1) {
                kov[i]=i+1;
            }
        }
        for (int i=0; i<n; i++) {
            if (kov[i]>i) continue;
            if ((mask & (1<<i))) {
                kov[i]=cel;
            } else if (ert!=-1 && kov[i]==ert) {
                kov[i]=cel2;
            }
        }

        ans=(ans+opt*solve(kov))%mod;
    }
    m[sor]=ans;
    return m[sor];
}
int main()
{
    cin >> val;
    for (long long i=2; i*i<=val; i++) {
        oszt(i);
    }
    if (val>1) {
        oszt(val);
    }

    n=hatv.size();

    vector<int> a;
    for (int i=0; i<n; i++) {
        a.push_back(-1);
    }
    cout << (solve(a)+mod-1)%mod << "\n";
    return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask1100/100
1Accepted4/41ms316 KiB
2Accepted4/42ms316 KiB
3Accepted4/46ms316 KiB
4Accepted4/46ms316 KiB
5Accepted4/41ms316 KiB
6Accepted4/41ms500 KiB
7Accepted4/44ms316 KiB
8Accepted4/46ms444 KiB
9Accepted4/443ms528 KiB
10Accepted4/443ms520 KiB
11Accepted4/450ms740 KiB
12Accepted4/4296ms408 KiB
13Accepted4/46ms316 KiB
14Accepted4/443ms756 KiB
15Accepted4/4101ms404 KiB
16Accepted4/46ms316 KiB
17Accepted4/44ms316 KiB
18Accepted4/44ms316 KiB
19Accepted4/443ms588 KiB
20Accepted4/41ms316 KiB
21Accepted4/4418ms396 KiB
22Accepted4/4418ms512 KiB
23Accepted4/4418ms316 KiB
24Accepted4/443ms564 KiB
25Accepted4/41ms316 KiB