【X-factor Chains】

题目需要让序列aa​​尽可能的长,且aiai+1a_i|a_{i+1},即ai×t=ai+1a_i\times t = a_{i+1}只要让tt尽可能小就行了,也就是tt是一个质数。

xx​分解质因数得x=p1α1p2α2...pkαkx=p_1^{\alpha_1}p_2^{\alpha_2}...p_k^{\alpha_k}​,即ai+1=ai×pja_{i+1}=a_i\times p_j​,只需要将质因数pjp_j​​排列组合就行了。

可以注意到质因数的全排列是一个多重组合数S=(αi)!(αi!)S=\frac{(\sum \alpha_i)!}{\prod (\alpha_i!)}

#include <bits/stdc++.h>
#define int long long
using namespace std;

const int N = 3e4 + 10;

int T, fac[N];
int x, total, sum, res;

void init() {
    fac[0] = 1;
    for (int i = 1; i <= 100; i++) fac[i] = fac[i - 1] * i;
}

signed main() {
    init();
    cin >> T;
    while (T--) {
        cin >> x;
        sum = total = 0;
        int tmp = x;
        int w = 1;
        for (int i = 2; i * i <= x; i++) {
            int cnt = 0;
            while (tmp % i == 0) {
                tmp /= i;
                cnt++;
            }
            if (cnt) {
                sum += cnt;
                w *= fac[cnt];
            }
        }
        if (tmp > 1) sum++;
        res = fac[sum] / w;

        cout << sum << " " << res << endl;
    }

    return 0;
}