zoukankan      html  css  js  c++  java
  • 略谈狄利克雷卷积

    1.一句话定义:

    狄利克雷卷积是形如f(x)=g(x)h(x)f(x)=g(x)*h(x)的式子(*是狄利克雷卷积符号,我也不知道手写叉乘行不行 ),它表示的含义为f(x)=dxg(d)×h(x/d)f(x)=sum_{d|x} g(d) imes h(x/d).

    2.性质:

    狄利克雷卷积满足交换律,结合律。如:
    f(x)g(x)=g(x)h(x),f(x)g(x)h(x)=f(x)(g(x)h(x))f(x)*g(x)=g(x)*h(x),f(x)*g(x)*h(x)=f(x)*(g(x)*h(x))

    还有一个很强的性质:
    f(x)=dxg(d)×h(x/d)f(x)=sum_{d|x}g(d) imes h(x/d)g,hfg,h均为积性函数,则f也是积性函数。(我的天啊!)
    下面给出证明:
    f(x)=dxg(d)×h(x/d)n,m设f(x)=sum_{d|x}g(d) imes h(x/d),有两个互质的正整数n,m。
    f(nm)=f(n)×f(m)则我们的目标是证明f(nm)=f(n) imes f(m)
    我们尝试一下从结论出发,
    f(nm)=f(n)×f(m)f(nm)=f(n) imes f(m)

    abnmg(ab)×h(nm/ab)=(  ang(a)×h(n/a)  )×(  bmg(b)×h(m/b) )sum_{ab|nm}g(ab) imes h(nm/ab)=(~~sum_{a|n}g(a) imes h(n/a)~~ ) imes( ~~ sum_{b|m}g(b) imes h(m/b) ~)

    abnmg(a)×h(n/a)×g(b)×h(m/b)=(  ang(a)×h(n/a)  )×(  bmg(b)×h(m/b) )(sum_{ab|nm}g(a) imes h(n/a) imes g(b) imes h(m/b)=(~~sum_{a|n}g(a) imes h(n/a)~~ ) imes( ~~ sum_{b|m}g(b) imes h(m/b) ~)(积性函数的性质得到)

    因为a,b互质,所以二者互不相干。如果我们把a看作一个常量,那么等式左边可化为ang(a)×h(n/a)×(  bmg(b)×h(m/b) )sum_{a|n}g(a) imes h(n/a) imes ( ~~ sum_{b|m}g(b) imes h(m/b) ~)=
    (ang(a)×h(n/a))×(  bmg(b)×h(m/b) )(sum_{a|n}g(a) imes h(n/a) ) imes ( ~~ sum_{b|m}g(b) imes h(m/b) ~)
    (感性理解即可)

    我们的每一变换都是恒等变化,所以我们也可以由下推到上,也就证明了这个性质的正确性。

    3.用途:

    狄利克雷卷积可以用来证明莫比乌斯反演。
    除此以外,我们还可以利用狄利克雷卷积的强大性质来加快求和。

    例题(POJ2480 Longge’s problem):

    Longge is good at mathematics and he likes to think about hard mathematical problems which will be solved by some graceful algorithms. Now a problem comes: Given an integer N(1 < N < 2^31),you are to calculate ∑gcd(i, N) 1<=i <=N.
    “Oh, I know, I know!” Longge shouts! But do you know? Please solve it.

    id(x)=xid(x)=x,
    dgcd(i,n),把d当做gcd(i,n),
    i=1ngcd(i,n)=i=1nd×[gcd(i/d,n/d)==1]=sum_{i=1}^n gcd(i,n)=sum_{i=1}^n d imes [gcd(i/d,n/d)==1]=
    dnd×i=1n/d[gcd(i,n/d)==1]=dnd×ϕ(n/d)=id(n)ϕ(n)sum_{d|n} d imes sum_{i=1}^{n/d} [gcd(i,n/d)==1]=sum_{d|n} d imes phi(n/d)=id(n)* phi(n)
    (狄利克雷卷积)
    那么,我们可以直接质因数分解n,利用上面的性质求解。
    下面有一个暴力,一个正解。

    //vio
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    using namespace std;
    typedef unsigned int ui;
    typedef long long ll; 
    int p[11],s[11],n;
    ll ans;
    void dfs(int k,int sum,int phi)//第k个质数,sum为约数d,phi为d的欧拉函数值。
    {
    	if(k>p[0])
    	{
    		ans+=n/sum*phi;
    		return;
    	}
    	dfs(k+1,sum,phi);
    	ll x=p[k];
    	for(int i=1;i<=s[k];i++)//p[k]^i
    	{
    		dfs(k+1,sum*x,(ll)phi*(x/p[k])*(p[k]-1));
    		x*=p[k];
    	}
    }
    int main()
    {
    	while(~scanf("%d",&n))
    	{
    		p[0]=0;
    		memset(s,0,sizeof(s));
    		int x=n;
    		for(ll i=2;i*i<=x;i++)
    			if(x%i==0)
    			{
    				p[++p[0]]=i;
    				do
    				{
    					x/=i;
    					s[p[0]]++;
    				}while(x%i==0);
    			}
    		if(x>1)p[++p[0]]=x,s[p[0]]=1;
    		ans=0;
    		dfs(1,1,1);
    		printf("%lld
    ",ans);
    	}
    	return 0;
    }
     
    
    //std
    #include<cstdio>
    using namespace std;
    typedef long long ll;
    ll ans;
    int n,p,s;
    int main()
    {
    	while(~scanf("%d",&n))
    	{
    		ans=1;
    		for(ll i=2;i*i<=n;i++)
    			if(n%i==0)
    			{
    				s=0;p=1;
    				do
    				{
    					n/=i;
    					p*=i;
    					++s;
    				}while(n%i==0);
    				ans*=(ll)(s*(i-1)*p/i)+p;
    			}
    		if(n>1)ans*=(ll)(n-1)+n;
    		printf("%lld
    ",ans);
    	}
    	return 0;
    }
    
  • 相关阅读:
    go并发和并行
    goroutine
    go并发
    wampserver配置问题
    获取字符串的长度
    mysql中事件失效如何解决
    Go语言中Goroutine与线程的区别
    Mosquitto服务器的日志分析
    phpexcel导出数据 出现Formula Error的解决方案
    Centos6.X 手动升级gcc
  • 原文地址:https://www.cnblogs.com/zsyzlzy/p/12373864.html
Copyright © 2011-2022 走看看