BZOJ2721 Violet5樱花(数论)
有(x+y)n!=xy。套路地提出x和y的gcd,设为d,令ad=x,bd=y。则有(a+b)n!=abd。此时d已是和a、b无关的量。由a与b互质,得a+b与ab互质,于是将a+b除过来得n!=abd/(a+b)。d/(a+b)可取的值不受a、b限制,那么只要满足ab|n!(a⊥b)就可以了。
将n!分解质因数,答案就很容易统计了。枚举质数数一下在n!中有几个即可。
#include<iostream> #include<cstdio> #include<cmath> #include<cstdlib> #include<cstring> #include<algorithm> using namespace std; int read() { int x=0,f=1;char c=getchar(); while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();} while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar(); return x*f; } #define N 1000010 #define P 1000000007 int n,prime[N],cnt=0,ans=1; bool flag[N]; int main() { #ifndef ONLINE_JUDGE freopen("bzoj2721.in","r",stdin); freopen("bzoj2721.out","w",stdout); const char LL[]="%I64d\n"; #else const char LL[]="%lld\n"; #endif n=read(); flag[1]=1; for (int i=2;i<=n;i++) { if (!flag[i]) prime[++cnt]=i; for (int j=1;j<=cnt&&prime[j]*i<=n;j++) { flag[prime[j]*i]=1; if (i%prime[j]==0) break; } } for (int i=1;i<=cnt;i++) { int w=0; for (int j=n;j;j/=prime[i]) w+=j/prime[i]; ans=1ll*ans*(w<<1|1)%P; } cout<<ans; return 0; }