Luogu1445 [Violet]樱花
https://www.luogu.com.cn/problem/P1445
数论
\[\frac{1}{x}+\frac{1}{y}=\frac{1}{n!} \\
(x+y)n!=xy\\
xy-(x+y)n!+(n!)^2=(n!)^2\\
(x-n!)(y-n!)=(n!)^2\\
令a=x-n!,b=y-n!\\
ab=(n!)^2
\]
计算每个数的因数种类、个数,可以每次除以它的最小质因数,复杂度\(1\)个\(log\)
从而计算\((n!)^2\)的因数个数
\(C++ Code:\)
#include<cstdio>
#include<iostream>
#include<algorithm>
#define mod 1000000007
#define N 1000005
#define ll long long
using namespace std;
int n,cnt,prime[N],c[N];
bool pri[N];
ll ans[N];
int main()
{
scanf("%d",&n);
for (int i=2;i<=n;i++)
{
if (!pri[i])
{
prime[++cnt]=i;
c[i]=i;
}
for (int j=1;j<=cnt;j++)
{
ll g=(ll)i*prime[j];
if (g>n)
break;
pri[g]=true;
c[g]=prime[j];
if (i%prime[j]==0)
break;
}
}
for (int i=1;i<=n;i++)
{
int k=i;
while (k^1)
{
ans[c[k]]++;
k/=c[k];
}
}
ll o=1;
for (int i=1;i<=n;i++)
o=o*(ans[i]+ans[i]+1)%mod;
cout << o << endl;
return 0;
}