数论——[Violet]樱花

题意:求方程 1/X+1/Y=1/(N!) 的正整数解的组数,其中N≤10^6。


设n!=z,y=z+d

1/x+1/y=1/z

1/x+1/(z+d)=1/z

(x+z+d)/(x*z+dx)=1/z

z(x+z+d)=x*z+dx

z^2+dz=dx

x=z^2/d+z

所以只要求有z^2有多少约数(即d的集合元素个数)即可


 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 #define N 1000003
 4 #define mo 1000000007
 5 #define ll long long
 6 using namespace std;
 7 int n,pri[N],mp[N],num[N],p[N];
 8 
 9 void oula()
10 {
11     for (int i=2;i<=N;i++)
12     {
13         if (!p[i]) pri[++pri[0]]=i,mp[i]=pri[0];
14         for (int j=1;i*pri[j]<=N&&j<=pri[0];j++)
15         {
16             p[i*pri[j]]=1;
17             if (i%pri[j]==0) break;
18         }
19     }
20 }
21 void cal(int x)
22 {
23     for (int i=1;pri[i]*pri[i]<=x;i++)
24     {
25         if (x%pri[i]==0)
26         {
27             while (x%pri[i]==0) num[i]++,x/=pri[i];
28         }
29         
30     }
31     if (x>1) num[mp[x]]++;
32 }
33 int main()
34 {
35     scanf("%d",&n);
36     oula();
37     for (int i=1;i<=n;i++)
38         cal(i);
39     ll ans=1;
40     for (int i=1;i<=pri[0];i++) ans=ans*(ll)(num[i]*2+1)%mo;//计算 
41     printf("%lld",ans);
42     return 0;
43 }
原文地址:https://www.cnblogs.com/71-111/p/9330886.html