知识点补档3

积性函数

f ( x ) 和 g ( x ) 均 为 积 性 函 数 , 则 h ( x ) = ∑ d ∣ x f ( d ) g ( x d ) 也 为 积 性 函 数 f(x)和g(x)均为积性函数,则h(x) =\sum_{d\mid x} {f(d)g( \frac{x}{d})}也为积性函数 f(x)g(x)h(x)=dxf(d)g(dx)

证明:

$ h(x)h(y) = \sum_{d \mid x} {f(d)g( \frac{x}{d})} \cdot \sum_{d \mid y} {f(d)g( \frac{y}{d})} $

h ( x ) h ( y ) = ∑ d ∣ x f ( d ) ⋅ ∑ d ∣ y f ( d ) ⋅ ∑ d ∣ x g ( x d ) ⋅ ∑ d ∣ y g ( y d ) h(x)h(y) = \sum_{d \mid x}f(d) \cdot \sum_{d \mid y} {f(d)} \cdot \sum_{d \mid x}{g( \frac{x}{d}}) \cdot \sum_{d \mid y}{g(\frac{y}{d})} h(x)h(y)=dxf(d)dyf(d)dxg(dx)dyg(dy)

$ \sum_{d \mid x}{g( \frac{x}{d}}) \cdot \sum_{d \mid y}{g(\frac{y}{d})} = [g(T_1)+g(T_2)+\cdots g(T_k)] \cdot [g(S_1)+g(S_2)+ \cdots g(S_p)]$ ( T i d = x ,    S j p = y ) (T_id = x , \; S_jp=y) (Tid=x,Sjp=y)

∑ d ∣ x g ( x d ) ⋅ ∑ d ∣ y g ( y d ) = g ( T 0 S 0 ) + g ( T 0 S 1 ) + ⋯ g ( T k S p ) \sum_{d \mid x}{g( \frac{x}{d}}) \cdot \sum_{d \mid y}{g( \frac {y}{d})} = g(T_0S_0)+g(T_0S_1)+ \cdots g(T_kS_p) dxg(dx)dyg(dy)=g(T0S0)+g(T0S1)+g(TkSp)

h ( x y ) = ∑ d ∣ x y f ( d ) g ( x y d ) h(xy) = \sum_{d \mid xy}{f(d)g( \frac{xy}{d})} h(xy)=dxyf(d)g(dxy)

∵ g c d ( x , y ) = 1 , 根 据 唯 一 分 解 定 理 x = T 1 n 1 ⋅ T 2 n 2 ⋯ T k n l y = S 1 m 1 ⋅ S 2 n 2 ⋯ S p m r      并 且 T i ≠ S j \because gcd(x,y)=1, 根据唯一分解定理 x= T_1^{n_1} \cdot T_2^{n_2} \cdots T_k^{n_l} \quad y = S_1^{m_1} \cdot S_2^{n_2} \cdots S_p^{m_r} \;\;并且 T_i \neq S_j gcd(x,y)=1,x=T1n1T2n2Tknly=S1m1S2n2SpmrTi=Sj ∴ x y = T 1 n 1 ⋅ T 2 n 2 ⋯ T k n l ⋅ S 1 m 1 ⋅ S 2 n 2 ⋯ S p m r    且 无 法 继 续 化 简 \therefore xy = T_1^{n_1} \cdot T_2^{n_2} \cdots T_k^{n_l} \cdot S_1^{m_1} \cdot S_2^{n_2} \cdots S_p^{m_r} \; 且无法继续化简 xy=T1n1T2n2TknlS1m1S2n2Spmr

∴ ∑ d ∣ x y g ( x y d ) = ∑ i = 1 , j = 1 g ( T i S j ) = ∑ d ∣ x g ( x d ) ⋅ ∑ d ∣ y g ( y d ) \therefore \sum_{d \mid xy}{g(\frac{xy}{d})}= \sum_{i=1,j=1}g(T_iS_j) = \sum_{d \mid x}{g( \frac{x}{d}}) \cdot \sum_{d \mid y}{g(\frac{y}{d})} dxyg(dxy)=i=1,j=1g(TiSj)=dxg(dx)dyg(dy)

$ \sum_{d \mid x}f(d) \cdot \sum_{d \mid y} {f(d)} = \sum_{d \mid xy}{f(d)};证明同上$

∴ h ( x ) h ( y ) = h ( x y ) \therefore h(x)h(y) = h(xy) h(x)h(y)=h(xy)

Dirichlet卷积

莫比乌斯函数:$\mu(n)= \begin{cases} 1 & n=1\ (-1)^k & c_{1,2,\cdots,k}=1\quad(n=\displaystyle\prod_{i=1}^k {p_i}^{c_i})\ 0 &c_i >1 \end{cases} $

定义两个数论函数 f , g f,g f,g D i r i c h l e t Dirichlet Dirichlet卷积为 ( f ∗ g ) ( n ) = ∑ d ∣ n f ( d ) g ( n d ) (f \ast g)(n) = \sum_{d \mid n}{f(d)g(\frac{n}{d})} (fg)(n)=dnf(d)g(dn)

ε \varepsilon ε D i r i c h l e t Dirichlet Dirichlet卷积的单位元,任何函数卷 ε \varepsilon ε都为其本身

ε ( n ) = ( μ ∗ 1 ) ( n ) = ∑ d ∣ n μ ( d ) = { 1 n = 1 0 n ≠ 1 \varepsilon(n) = (\mu*1)(n) = \sum_{d \mid n}{\mu(d)} = \begin{cases} 1 & n=1 \\ 0 & n \neq 1\end{cases} ε(n)=(μ1)(n)=dnμ(d)={10n=1n=1

莫比乌斯反演

知识点

f ( n ) , g ( n ) f(n),g(n) f(n),g(n)为两个数论函数

若有 f ( n ) = ∑ d ∣ n g ( d ) f(n) = \sum_{d \mid n}{g(d)} f(n)=dng(d), 则有 g ( n ) = ∑ d ∣ n μ ( d ) f ( n d ) g(n) = \sum_{d \mid n}{\mu(d)f(\frac{n}{d}}) g(n)=dnμ(d)f(dn)

证明: f ( n ) = ( g ∗ 1 ) ( n ) ( f ∗ μ ) ( n ) = ( g ∗ μ ∗ 1 ) ( n ) = g ( n ) f(n) = (g *1)(n) \qquad (f*\mu)(n) = (g*\mu*1)(n ) = g(n) f(n)=(g1)(n)(fμ)(n)=(gμ1)(n)=g(n)

推广:设 f , g f, g f,g为两个数论函数, t t t为一个完全积性函数,且 t ( 1 ) = 1 t(1) = 1 t(1)=1,有 f ( n ) = ∑ k = 1 n t ( k ) g ( ⌊ n k ⌋ ) f(n) = \sum_{k=1}^{n} t(k)g( \lfloor \frac {n}{k} \rfloor) f(n)=k=1nt(k)g(kn)

则有: g ( n ) = ∑ k = 1 n μ ( k ) t ( k ) f ( ⌊ n k ⌋ ) g(n)=\sum_{k=1}^{n}\mu(k)t(k)f(\lfloor \frac{n}{k} \rfloor) g(n)=k=1nμ(k)t(k)f(kn)

还有另一种形式: g ( n ) = ∑ n ∣ d x f ( d ) g(n) = \sum_{n \mid d}^{x}f(d) g(n)=ndxf(d) f ( n ) = ∑ n ∣ d x g ( d ) μ ( d n ) f(n)=\sum_{n \mid d}^{x}g(d) \mu(\frac{d}{n}) f(n)=ndxg(d)μ(nd) x x x是一个限定范围

证明: g ( n ) = ∑ n ∣ d x f ( d ) = ∑ n ∣ d x ∑ d ∣ e x g ( e ) μ ( e d ) = ∑ n ∣ d x [ μ ( d n ) ∑ d ∣ e x g ( e ) ] = g ( n ) g(n) = \sum_{n \mid d}^{x}f(d) = \sum_{n \mid d}^{x} \sum_{d \mid e}^{x} g(e) \mu(\frac{e}{d}) = \sum_{n \mid d}^{x}[\mu(\frac{d}{n}) \sum_{d \mid e}^{x}g(e)] = g(n) g(n)=ndxf(d)=ndxdexg(e)μ(de)=ndx[μ(nd)dexg(e)]=g(n)

例题:BZOJ 2154

给定 n , m n,m n,m,求 ∑ i = 1 n ∑ j = 1 m l c m ( i , j ) \sum_{i=1}^{n}\sum_{j=1}^{m}lcm(i,j) i=1nj=1mlcm(i,j) ( n < m nn<m)
题 解 : ∑ i = 1 n ∑ j = 1 m l c m ( i , j ) = ∑ i = 1 n ∑ j = 1 m i j g c d ( i , j ) 进 行 一 个 神 奇 的 操 作 ∑ d = 1 n ∑ i = 1 n ∑ j = 1 m [ g c d ( i , j ) = d ] i j d = ∑ d = 1 n ∑ i = 1 n ∑ j = 1 m [ g c d ( i , j ) = 1 ] i j d ∴ 令 a n s = ∑ d = 1 n ∑ i = 1 n / d ∑ j = 1 m / d [ g c d ( i , j ) = 1 ] i j 现 在 观 察 这 一 部 分 ∑ i = 1 n / d ∑ j = 1 m / d [ g c d ( i , j ) = 1 ] i j 令 : f ( d ) = ∑ i = 1 x ∑ j = 1 y [ g c d ( i , j ) = d ] i j 根 据 据 说 是 莫 比 乌 斯 反 演 的 一 个 常 见 套 路 设 : g ( d ) = ∑ i = 1 x ∑ j = 1 y [ d ∣ g c d ( i , j ) ] i j = d 2 ∑ i = 1 x ∑ j = 1 y [ 1 ∣ g c d ( i , j ] i j ∴ g ( d ) = d 2 ∑ i = 1 x ∑ j = 1 y i j 这 一 部 分 可 以 O ( 1 ) 求 再 进 行 一 个 神 奇 的 观 察 和 推 理 : f ( 1 ) = ∑ i = 1 x μ ( i ) g ( i ) = ∑ i = 1 x μ ( i ) i 2 ∑ i = 1 x / d ∑ j = 1 y / d i j 我 们 就 可 以 数 论 分 块 来 做 了 , 预 处 理 μ ( i ) ∗ i 2 的 前 缀 和 , 复 杂 度 为 O ( n ) 题解: \quad \sum_{i=1}^{n}\sum_{j=1}^{m}lcm(i,j) = \sum_{i=1}^{n}\sum_{j=1}^{m}{\frac{ij}{gcd(i,j)}}\\ 进行一个神奇的操作\\ \sum_{d=1}^{n}\sum_{i=1}^{n}\sum_{j=1}^{m}[gcd(i,j) = d] \frac{ij}{d} = \sum_{d=1}^{n}\sum_{i=1}^{n}\sum_{j=1}^{m}[gcd(i,j) = 1]ijd \\ \therefore 令 ans = \sum_{d=1}^{n}\sum_{i=1}^{n/d}\sum_{j=1}^{m/d}[gcd(i,j)=1]ij \\ 现在观察这一部分 \quad \sum_{i=1}^{n/d}\sum_{j=1}^{m/d}[gcd(i,j)=1]ij \\ 令: f(d) = \sum_{i=1}^{x}\sum_{j=1}^{y}[gcd(i,j)=d]ij \\ 根据据说是莫比乌斯反演的一个常见套路 \\ 设:g(d) = \sum_{i=1}^{x}\sum_{j=1}^{y}[d \mid gcd(i,j)]ij = d^2\sum_{i=1}^{x}\sum_{j=1}^{y}[1 \mid gcd(i,j]ij \\ \therefore g(d) = d^2\sum_{i=1}^{x}\sum_{j=1}^{y}ij \quad 这一部分可以O(1)求 \\ 再进行一个神奇的观察和推理:\\ f(1) = \sum_{i=1}^{x} \mu(i)g(i) = \sum_{i=1}^{x}\mu(i)i^2\sum_{i=1}^{x/d}\sum_{j=1}^{y/d}ij \\ 我们就可以数论分块来做了,预处理\mu(i)*i^2的前缀和,复杂度为O(n) i=1nj=1mlcm(i,j)=i=1nj=1mgcd(i,j)ijd=1ni=1nj=1m[gcd(i,j)=d]dij=d=1ni=1nj=1m[gcd(i,j)=1]ijdans=d=1ni=1n/dj=1m/d[gcd(i,j)=1]iji=1n/dj=1m/d[gcd(i,j)=1]ijf(d)=i=1xj=1y[gcd(i,j)=d]ijg(d)=i=1xj=1y[dgcd(i,j)]ij=d2i=1xj=1y[1gcd(i,j]ijg(d)=d2i=1xj=1yijO(1)f(1)=i=1xμ(i)g(i)=i=1xμ(i)i2i=1x/dj=1y/dijμ(i)i2O(n)
AC代码:

#include
#include
#include
#include

using namespace std;
#define MOD 20101009
#define MAX 12000000
#define ll long long

inline int read()
{
    int x=0,t=1;char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
    if(ch=='-')t=-1,ch=getchar();
    while(ch<='9'&&ch>='0')x=x*10+ch-48,ch=getchar();
    return x*t;
}
int mu[MAX],pri[MAX],tot;
bool zs[MAX];
int n,m;
int G[MAX],ans;
int smu[MAX],sqr[MAX];
void Getmu()
{
    zs[1]=true;mu[1]=1;
    for(int i=2;i<=n;++i)
    {
        if(!zs[i]){pri[++tot]=i;mu[i]=-1;}
        for(int j=1;j<=tot&&i*pri[j]<=n;++j)
        {
            zs[i*pri[j]]=true;
            if(i%pri[j])mu[i*pri[j]]=-mu[i];
            else{mu[i*pri[j]]=0;break;}
        }
    }
    for(int i=1;i<=n;++i)smu[i]=(smu[i-1]+mu[i]+MOD)%MOD;
}
int Solve(int xx,int yy)
{
    long long ans=0;
    int i=1,j;
    while(i<=xx)
    {
        j=min(xx/(xx/i),yy/(yy/i));
        int GG=1ll*(1ll*(1+xx/i)*(xx/i)/2%MOD)*(1ll*(1+yy/i)*(yy/i)/2%MOD)%MOD;
        ans+=1ll*(sqr[j]-sqr[i-1])%MOD*GG%MOD;
        ans%=MOD;
        i=j+1;
    }
    return (ans+MOD)%MOD;
}
int main()
{
    n=read();m=read();
    if(n>m)swap(n,m);
    Getmu();
    for(int i=1;i<=n;++i)sqr[i]=(sqr[i-1]+1ll*i*i%MOD*mu[i]%MOD+MOD)%MOD;
    int i=1,j;
    while(i<=n)
    {
        j=min(n/(n/i),m/(m/i));
        int t=1ll*(i+j)*(j-i+1)/2%MOD;
        ans=(ans+1ll*Solve(n/i,m/i)*t%MOD)%MOD;
        i=j+1;
    }
    printf("%d\n",ans);
    return 0;
}

杜教筛

对于数论函数 f f f,计算 S ( n ) = ∑ i = 1 n f ( i ) S(n) = \sum_{i=1}^{n}f(i) S(n)=i=1nf(i),要构造一个 S ( n ) S(n) S(n)关于 S ( ⌊ n i ⌋ ) S(\lfloor \frac{n}{i} \rfloor) S(in)的递推式

对于任意一个数论函数 g g g,必有:
∑ i = 1 n ∑ d ∣ i f ( d ) g ( i d ) = ∑ i = 1 n ∑ j = 1 ⌊ n i ⌋ g ( i ) f ( j ) = ∑ i = 1 n g ( i ) ∑ j = 1 ⌊ n i ⌋ f ( j ) = ∑ i = 1 n g ( i ) S ( ⌊ n i ⌋ ) \sum_{i=1}^{n}\sum_{d\mid i}f(d)g(\frac{i}{d})=\sum_{i=1}^{n}\sum_{j=1}^{\lfloor \frac{n}{i}\rfloor}g(i)f(j)=\sum_{i=1}^{n}g(i)\sum_{j=1}^{\lfloor \frac{n}{i}\rfloor}f(j)=\sum_{i=1}^{n}g(i)S(\lfloor \frac{n}{i}\rfloor) i=1ndif(d)g(di)=i=1nj=1ing(i)f(j)=i=1ng(i)j=1inf(j)=i=1ng(i)S(in)
那么可以得到递推式:
g ( 1 ) S ( n ) = ∑ i = 1 n ( f ∗ g ) ( i ) − ∑ i = 2 n g ( i ) S ( ⌊ n i ⌋ ) g(1)S(n)=\sum_{i=1}^{n}(f*g)(i)-\sum_{i=2}^{n}g(i)S(\lfloor \frac{n}{i}\rfloor) g(1)S(n)=i=1n(fg)(i)i=2ng(i)S(in)
假如可以快速对 ( f ∗ g ) ( i ) (f*g)(i) (fg)(i) g ( i ) g(i) g(i)完成求和,可根据 ⌊ n i ⌋ \lfloor \frac{n}{i}\rfloor in取值进行分段,计算一个 S ( n ) S(n) S(n)的复杂度为 O ( n ) O(\sqrt{n}) O(n )

你可能感兴趣的:(数论)