HDU 6428 2018HDU多校赛 第十场 Calculate(莫比乌斯反演 + 积性 + 线性筛)

 

 

题意简单粗暴,让你求  \large \sum_{i=1}^{A}\sum_{j=1}^{B}\sum_{k=1}^{C}\phi(gcd(i,j^2,k^3))\ mod\ 2^{30}

与gcd有关,一般来说都是要上莫比乌斯来反演一下了。具体来说,我们先来推一些式子:

                                              \large \begin{align*} \phi(n) &=\sum_{d|n}\mu(d)(n/d) \\ &= \sum_{d|n}\mu(d)\sum_{d'|n/d}\phi(d') \\ &= \sum_{dd'|n}\mu(d)\phi(d') \\ &= \sum_{d|n}\sum_{d'|d}\mu(d')\phi(d/d') \\ &= \sum_{d|n} (\mu*\phi)(d) \end{align*}

那么,原式我们就可以写成:\large \sum_{i=1}^{A}\sum_{j=1}^{B}\sum_{k=1}^{C}\sum_{d|i,d|j^2,d|k^3}(\mu*\phi)(d)\ mod\ 2^{30}

然后我们再交换一下求和次序:\large \sum_{d=1}^{A}(\mu*\phi)(d)\sum_{i=1,d|i}^{A}\sum_{j=1,d|j^2}^{B}\sum_{k=1,d|k^3}^{C}1\ mod\ 2^{30}

对于后面这个东西,我们可以发现,对于一个数字x^k,他能够被d整除,当且仅当\large pi^{\lceil\frac{ai}{k}\rceil}|x,其中pi表示d分解质因子的每一个数字,ai表示对应pi的指数。那么我么令\large f_{k}(i)=\prod_{i=1}^{n}pi^{\lceil\frac{ai}{k}\rceil},那么最后的答案就是:

                          \large ans=\sum_{d=1}^{A}(\mu*\phi)(d)\lfloor\frac{A}{f_1(d)}\rfloor\lfloor\frac{B}{f_2(d)}\rfloor\lfloor\frac{C}{f_3(d)}\rfloor\ mod\ 2^{30}

我们注意到,\large (\mu*\phi)(d)是欧拉函数和莫比乌斯函数的迪利克雷卷积,根据定理,积性函数的迪利克雷卷积也是积性函数,因此\large (\mu*\phi)(d)具有积性。而\large f_1(d)\large f_2(d)\large f_3(d)是类似于d分解质因子的形式,显然也是具有积性的,因此我们可以构造线性筛,在O(A)的时间复杂度内解决这道题。所谓积性,就是在互质的时候f(xy)=f(x)*f(y),关键是要求不互质的时候以及质数本身的表达式。

我们令\large h(d)= (\mu*\phi)(d),根据我们之前的推导:\large \phi(n)=\sum_{d|n} h(d),那么有:

                                                    \large \phi(p^n)=\phi(p^{n-1})+h(p^n)

于是:                                         \large \begin{align*} h(p^n)&=\phi(p^n)-\phi(p^{n-1}) \\ &= (p-1)p^{n-1}-(p-1)p^{n-2} \\ &= (p-1)(p^{n-1}-p^{n-2}) \\ &=(p-1)p^{n-2}(p-1) \\ &=(p-1)^2p^{n-2} \end{align*}

那么:                                    \large \begin{align*}h(1) &= 1 \\ h(p) &= p-2 \\ h(p^n) &= (p-1)^2p^{n-2} \\ h(p_1^{n_1}p_2^{n_2})&=h(p_1^{n_1})h(p_2^{n_2}) \\ &... \\ &... \end{align*}

 

接下来再看这个\large f_k(n),这个就是在分解质因子的过程中,记录一个deg,表示当前质因子的指数。每次这个质因子加一,当发现它%k之后是1,说明此时除以k向上取整会变大,于是\large f_k(n)乘上当前质因子。具体见代码:

#include<bits/stdc++.h>
#define LL long long
#define mod 998244353
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define INF 0x3f3f3f3f
#define sf(x) scanf("%d",&x)
#define sc(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define clr(x,n) memset(x,0,sizeof(x[0])*(n+5))
#define file(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout)

using namespace std;

const int N = 1e7 + 10;

unsigned int p[N],phmu[N],f2[N],f3[N],last[N],deg[N];
bool isp[N];

void init()
{
    int sz=0;
    phmu[1]=f2[1]=f3[1]=last[N]=1;
    for(int i=2;i<N;i++)
    {
        if(!isp[i])
        {
            f2[i]=f3[i]=p[++sz]=i;
            phmu[i]=i-2; last[i]=deg[i]=1;
        }
        for(int j=1;j<=sz&&(LL)i*p[j]<N;j++)
        {
            int x=i*p[j];
            isp[x]=1;
            if(i%p[j]==0)
            {
                last[x]=last[i];
                deg[x]=deg[i]+1;
                if (last[i]>1) phmu[x]=phmu[last[i]]*phmu[x/last[i]];
                else
                {
                    if (i>p[j]) phmu[x]=phmu[i]*p[j];
                        else phmu[x]=(p[j]-1)*(p[j]-1);
                }
                f2[x]=f2[i]*(deg[x]%2==1?p[j]:1);
                f3[x]=f3[i]*(deg[x]%3==1?p[j]:1);
                break;
            } else
            {
                deg[x]=1;
                last[x]=i;
                f2[x]=f2[i]*f2[p[j]];
                f3[x]=f3[i]*f3[p[j]];
                phmu[x]=phmu[i]*phmu[p[j]];
            }
        }
    }

}

int main()
{
    init();
    int T; sf(T);
    while(T--)
    {
        int a,b,c;
        sc(a,b,c);
        unsigned int ans=0;
        for(int i=1;i<=a;i++)
            ans=(ans+phmu[i]*(a/i*(b/f2[i])*(c/f3[i])));
        printf("%d\n",ans&((1<<30)-1));
    }
    return 0;
}

 

 

                                    

                                    

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值