题意:
1
/
N
!
=
1
/
X
+
1
/
Y
(
0
<
x
<
=
y
)
1/N! = 1/X + 1/Y(0<x<=y)
1/N!=1/X+1/Y(0<x<=y),给出
N
N
N,求满足条件的整数解的数量。例如:
N
=
2
,
1
/
2
=
1
/
3
+
1
/
6
,
1
/
2
=
1
/
4
+
1
/
4
N = 2,1/2 = 1/3 + 1/6,1/2 = 1/4 + 1/4
N=2,1/2=1/3+1/6,1/2=1/4+1/4。由于数量可能很大,输出
m
o
d
mod
mod
1
0
9
+
7
10^9 + 7
109+7。
思路:
尝试变换式子:
1
n
!
=
1
x
+
1
y
=
x
+
y
x
y
\frac{1}{n!} = \frac{1}{x} + \frac{1}{y} = \frac{x+y}{xy}
n!1=x1+y1=xyx+y
则:
n
!
=
x
y
x
+
y
n! = \frac{xy}{x+y}
n!=x+yxy
x
y
−
x
n
!
−
y
n
!
=
0
xy - xn! - yn! = 0
xy−xn!−yn!=0
推出:
(
x
−
n
!
)
(
y
−
n
!
)
=
(
n
!
)
2
(x-n!)(y-n!) = (n!)^2
(x−n!)(y−n!)=(n!)2
因为
1
n
!
=
1
x
+
1
y
\frac{1}{n!} = \frac{1}{x} + \frac{1}{y}
n!1=x1+y1
故
x
,
y
>
n
!
x,y > n!
x,y>n!
则x,y的数目等价于
(
n
!
)
2
(n!)^2
(n!)2的因子个数
又
x
<
=
y
x<=y
x<=y故 最终答案为(因子个数+
1
1
1)/
2
2
2,向下取整。
处理因子个数可以用因子个数定理,对于
n
!
n!
n!,可以用线性筛处理,总复杂度:
O
(
n
l
o
g
n
)
O(nlogn)
O(nlogn)
代码:
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
const int A = 1e6 + 10;
bool vis[A];
ll fast_mod(ll n,ll m){
ll res = 1;
while(m){
if(m&1) res = (res*n)%mod;
n = n*n%mod;
m >>= 1;
}
return res;
}
int main(){
ll ans = 1;
int n;
scanf("%d",&n);
for(int i=2 ;i<=n ;i++){
if(!vis[i]){
int cnt = 0;
for(int j=i ;j<=n ;j+=i){
vis[j] = 1;
int now = j;
while(now%i == 0){
now /= i;
cnt++;
}
}
ans = ans*(1LL*2*cnt+1)%mod;
}
}
ll inv2 = fast_mod(2,mod-2);
ans = (ans+1)%mod*inv2%mod;
if(ans<0) ans += mod;
printf("%I64d\n",ans);
return 0;
}