NOIP 模拟 七十一 (2)

NOIP 模拟 七十一

玄学,每个点解法不同。

#include<bits/stdc++.h> #define int long long #define mod 1000000007 #define inv12 83333334 using namespace std; int n,m,k,ans=1; inline int qpow(int a,int b) { int base=1; while(b) { if(b&1)base=base*a%mod; a=a*a%mod; b>>=1; } return base; } inline int pow1(int x){return x%mod*((x+1)%mod)%mod*(2*x%mod+1)%mod;} signed main() { freopen("vegetable.in","r",stdin); freopen("vegetable.out","w",stdout); scanf("%lld%lld%lld",&n,&m,&k); if(m==k) { for(int i=1;i<=k;++i)ans=ans*((n-i+1)%mod)%mod; for(int i=k;i;--i)ans=ans*qpow(i,mod-2)%mod; printf("%lld\n",ans);return 0; } if(m==2 and k==1) { ans=0; for(int l=1,r;l<=n;l=r+1) { r=n/(n/l); ans=(ans+((r-l+1)%mod)*(n/l%mod)%mod)%mod; } printf("%lld\n",(ans-n%mod+mod)%mod);return 0; } if(m==3 and k==1){printf("%lld\n",(n/3)%mod);return 0;} if(m==4 and k==1) { if(n<=5)printf("%lld\n",1ll); else { ans=0;for(int i=2;i<=7;++i) { if(i==6)continue; ans=(ans+n/(3*i))%mod; }ans=(ans+n/10)%mod; printf("%lld\n",ans); } return 0; } if(m==4 and k==2) { if(n<=6)cout<<1<<endl; if(n==7)cout<<3<<endl; if(n==8)cout<<6<<endl; if(n==9)cout<<9<<endl; if(n==10)cout<<10<<endl; if(n>=11)cout<<(n/11+n/29)%mod<<endl; return 0; } if(m==3 and k==2) { ans=0; for(int l=1,r;l<=n;l=r+1) { r=n/(n/l);int tmp=0; int zhi1=(l-1)/2,zhi2=(r-1)/2; if(!(l&1))tmp=(tmp+zhi1)%mod,zhi1++; if(r&1)tmp=(tmp+zhi2)%mod,--zhi2; if(zhi1<=zhi2) tmp=(tmp+(zhi1+zhi2)%mod*((zhi2-zhi1+1)%mod)%mod)%mod; ans=(ans+tmp*(n/l%mod)%mod)%mod; } printf("%lld\n",ans);return 0; } if(m==4 and k==3) { ans=0; for(int l=1,r;l<=n;l=r+1) { r=n/(n/l);int tmp=0; tmp=(tmp+(pow1(r)-pow1(l-1)+mod)%mod*inv12%mod*2%mod)%mod; tmp=(tmp-((l+r)%mod)*((r-l+1)%mod)%mod*inv12%mod*6%mod*6%mod+mod)%mod; tmp=(tmp+(r-l+1)%mod*5%mod)%mod; tmp=(tmp+((r/2)-(l+1)/2+1)%mod*3%mod)%mod; tmp=(tmp+(r/3-(l+2)/3+1)%mod*4%mod)%mod; tmp=tmp*inv12%mod; ans=(ans+tmp*((n/l)%mod)%mod)%mod; } if(n==4)ans=1;if(n==5)ans=5; printf("%lld\n",ans);return 0; } }

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zzyfgp.html