https://www.luogu.org/problem/P1445
很容易得$x=n!y/y-n!$
设k=y-n!
则原式x=n!(k+n!)/k
x=n!^2+n!k/k
x=n!^2/k+n!
∴只有k|n^2时x才为正数
∴k的个数即是x、y的个数
易看出k的个数即n!^2约数的个数
于是这道题转换为求n^2的约数的个数有多少
公式:百度百科自己搜
#include<bits/stdc++.h> #define rep(i,a,b) for(int i=a;i<=b;i++) #define MAXN 1000050 #define int long long #define N 1000000 using namespace std; const int mod=1e9+7; inline int read(){ int x=0,f=1; char ch=getchar(); while('0'>ch || ch>'9'){if(ch=='-') f=-1; ch=getchar();} while('0'<=ch && ch<='9') x=(x<<1)+(x<<3)+ch-'0',ch=getchar(); return x*f; } int n,pre[MAXN],book[MAXN],cnt,res,f[MAXN],ans=1; void shai(){ rep(i,2,N){ if(!book[i]){ book[i]=i; pre[++cnt]=i; } rep(j,1,cnt){ if(i*pre[j]>N || pre[j]>book[i]) break; book[i*pre[j]]=pre[j]; } } } main(){ n=read(); shai(); rep(i,2,n){ int x=i; while(x!=1)f[book[x]]++,x/=book[x]; } rep(i,2,n) f[i]*=2; rep(i,1,n) ans=(ans*(f[i]+1))%mod; printf("%lld",ans); return 0; }