题解:P1445 [Violet] 樱花

推柿子。

\[\frac{1}{x} + \frac{1}{y} = \frac{1}{n!} \]

\[\frac{x + y}{x \times y} = \frac{1}{n!} \]

\[n!\times (x + y) = x \times y \]

\[x \times y - n!x - n!y = 0 \]

\[n!^2 + x \times y - n!x - n!y = n!^2 \]

\[(n! - x)(n! - y) = n!^2 \]

显然 \((n! - x)\)\((n! - y)\) 分别是两个乘积为 \(n! ^ 2\)\(n! ^ 2\) 的因子。

那么统计 \(n! ^ 2\) 的因数个数即可。

#include <bits/stdc++.h>
#define int long long
#define pii pair<int, int>
#define FRE(x) freopen(x ".in", "r", stdin), freopen(x ".out", "w", stdout)
#define ALL(x) x.begin(), x.end()
using namespace std;

inline void cmax(int& x, int c) {
    x = max(x, c);
}
inline void cmin(int& x, int c) {
    x = min(x, c);
}

int _test_ = 1;

const int N = 1e6 + 5, mod = 1e9 + 7;

int n;
bool vis[N];
vector<int> p;
int mp[N];

void s(int n) {
    for (register int i = 2; i <= n; i++) {
        if (!vis[i])
            p.push_back(i);
        for (int x : p) {
            if (i * x > n)
                break;
            vis[i * x] = true;
            if (i % x == 0)
                break;
        }
    }
}

void init() {}

void clear() {}

void solve() {
    cin >> n;
    s(n);
    for (int x : p) {
        for (int i = x; i <= n; i += x) {
            int t = i, ans = 0;
            while (t % x == 0)
                ans++, t /= x;
            if (ans)
                mp[x] = (mp[x] + 2 * ans) % mod;
        }
    }
    int ans = 1;
    for (int i = 1; i <= n; i++)
        ans = (ans * (mp[i] + 1)) % mod;
    cout << ans;
}

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    // cin >> _test_;
    init();
    while (_test_--) {
        clear();
        solve();
    }
    return 0;
}
posted @ 2025-01-12 22:20  Reveriean  阅读(20)  评论(0)    收藏  举报