【LG1445】樱花
题面
题解
[frac 1x+frac 1y=frac 1{n!}\
frac{x+y}{xy}=frac 1{n!}\
n!(x+y)=xy\
xy-n!(x+y)=0\
(n!)^2+xy-n!(x+y)=(n!)^2\
(x-n!)(y-n!)=(n!)^2
]
设(a=x-n!,b=y-n!)
[ab=(n!)^2
]
枚举约数就好啦
代码
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
const int Mod = 1e9 + 7;
const int MAX_N = 1e6 + 5;
void pls(int &x, int y) { x += y; if (x >= Mod) x -= Mod; }
bool is_prime[MAX_N];
int N = 1e6, prime[MAX_N], num, ans = 1;
void sieve() {
for (int i = 1; i <= N; i++) is_prime[i] = 1;
is_prime[1] = 0;
for (int i = 2; i <= N; i++) {
if (is_prime[i]) prime[++num] = i;
for (int j = 1; prime[j] * i <= N && j <= num; j++) {
is_prime[i * prime[j]] = 0;
if (!(i % prime[j])) break;
}
}
}
int main () {
sieve();
cin >> N;
for (int i = 1; i <= num; i++) {
if (prime[i] > N) break;
int cnt = 0;
for (long long j = prime[i]; j <= N; j = j * prime[i]) pls(cnt, 1ll * N / j);
pls(cnt, cnt), pls(cnt, 1);
ans = 1ll * ans * cnt % Mod;
}
printf("%d
", ans);
return 0;
}