Date:2021.12.29
题意:给定一个整数 n,求有多少正整数数对 (x,y) 满足 1 x \frac{1}{x} x1 + 1 y \frac{1}{y} y1 = 1 n ! \frac{1}{n!} n!1,答案对 1 0 9 10^9 109+7 取模。
1≤ n ≤ 1 0 6 10^6 106
思路:推公式如下图。前置知识:阶乘分解
代码如下:
//由公式 等价于求(n!)^2的约数个数
#include <iostream>
#include <cstring>
#include <algorithm>
#include <map>
using namespace std;
typedef long long LL;
const int N = 1e6+10,mod=1e9+7;
LL n;
LL cnt,prime[N];
bool st[N];
map<LL,LL>q;
void init()
{
for(int i=2;i<=n;i++)
{
if(!st[i]) prime[cnt++]=i;
for(int j=0;prime[j]<=n/i;j++)
{
st[prime[j]*i]=true;
if(i%prime[j]==0) break;
}
}
}
int main()
{
cin>>n;
init();
for(int i=0;i<cnt;i++)
{
LL res=0,p=prime[i],t=n;
while(t)
{
res+=t/p;
t/=p;
}
q[prime[i]]+=res;
}
LL sum=1;
for(int i=0;i<cnt;i++)
sum=sum*(2*q[prime[i]]%mod+1)%mod;
cout<<sum;
}