Mobius反演定理-BZOJ2154
This article is made by Jason-Cow.
Welcome to reprint.
But please post the article's address.
莫比乌斯定理(未完待续......):
形式1:
形式2:
引理:
证明1:
右边=带入左边等式,得
又
当且仅当 :
,即
时,上式非
所以,成立。
bzoj2154
时间复杂度
换元:令
/*
*/
此题的精髓就一个字,模
1 #include <algorithm> 2 #include <iostream> 3 #include <cstring> 4 #include <cstdlib> 5 #include <cstdio> 6 #include <vector> 7 #include <cmath> 8 #include <queue> 9 #include <map> 10 #include <set> 11 using namespace std; 12 #define file(x) freopen(x".in","r",stdin),freopen(x".out","w",stdout) 13 14 const int mod=20101009,maxn=1e7+10; 15 int f[maxn],p[maxn],flag[maxn],cnt,S[maxn]; 16 void init(int n,int m){ 17 f[1]=1; 18 for(int i=2;i<=n;i++) { 19 if(!flag[i])p[++cnt]=i,f[i]=(1-i)%mod; 20 for(int j=1;j<=cnt && i*p[j]<=n;j++) { 21 flag[i*p[j]]=1; 22 if(i%p[j]==0){f[i*p[j]]=f[i]%mod;break;} 23 f[i*p[j]]=((long long)(f[i]%mod)*(f[p[j]]%mod))%mod; 24 } 25 } 26 for(int i=1;i<=m;i++)S[i]=((S[i]%mod)+((S[i-1]+i)%mod))%mod; 27 } 28 29 int main(){ 30 int n,m;scanf("%d%d",&n,&m);if(n>m)swap(n,m); 31 init(n,m); 32 int ans=0; 33 for(int Q=1;Q<=n;Q++) 34 ans=(ans+(((Q%mod)*(long long)f[Q]*(((long long)S[n/Q]*S[m/Q])%mod))%mod)%mod)%mod; 35 printf("%d\n",(ans+mod)%mod); 36 return 0; 37 }
f
~~Jason_liu O(∩_∩)O