Luogu P6055 [RC-02] GCD(莫比乌斯反演,杜教筛)(这题乐死我了,真就图一乐呗)

Posted 繁凡さん

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Luogu P6055 [RC-02] GCD(莫比乌斯反演,杜教筛)(这题乐死我了,真就图一乐呗)相关的知识,希望对你有一定的参考价值。

整理的算法模板合集: ACM模板

点我看算法全家桶系列!!!

实际上是一个全新的精炼模板整合计划


Weblink

https://www.luogu.com.cn/problem/P6055

Problem

给出 N N N,求:

∑ i = 1 N ∑ j = 1 N ∑ p = 1 ⌊ N ȷ ⌋ ∑ q = 1 ⌊ N j ⌋ [ gcd ⁡ ( i , j ) = 1 ] [ gcd ⁡ ( p , q ) = 1 ] \\sum_{i=1}^{N} \\sum_{j=1}^{N} \\sum_{p=1}^{\\left\\lfloor\\frac{N}{\\jmath}\\right\\rfloor} \\sum_{q=1}^{\\left\\lfloor\\frac{N}{j}\\right\\rfloor}[\\operatorname{gcd}(i, j)=1][\\operatorname{gcd}(p, q)=1] i=1Nj=1Np=1ȷNq=1jN[gcd(i,j)=1][gcd(p,q)=1]

答案模 998244353 998244353 998244353

Solution

这题真是乐死我了,真就图一乐呗

上来怎么看这个 j j j 怎么不顺眼,这不先把 j j j 直接丢回去 ???

然后这题就没了…

随便反演一下,杜教筛随便搞搞就完事了

      ∑ i = 1 N ∑ j = 1 N ∑ p = 1 ⌊ N j ⌋ ∑ q = 1 ⌊ N j ⌋ [ gcd ⁡ ( i , j ) = 1 ] [ gcd ⁡ ( p , q ) = 1 ] = ∑ i = 1 N ∑ j = 1 N ∑ p = 1 N ∑ q = 1 N [ gcd ⁡ ( i , j ) = 1 ] [ gcd ⁡ ( p , q ) = j ] = ∑ i = 1 N ∑ p = 1 N ∑ q = 1 N [ gcd ⁡ ( i , p , q ) = 1 ] = ∑ i = 1 N ∑ p = 1 N ∑ q = 1 N ∑ d ∣ gcd ⁡ ( i , p , q ) μ ( d ) = ∑ d = 1 N ∑ i = 1 N ∑ p = 1 N ∑ q = 1 N [ d ∣ i ] [ d ∣ p ] [ d ∣ q ] μ ( d ) = ∑ d = 1 N ∑ i = 1 ⌊ N d ⌋ ∑ p = 1 ⌊ N d ⌋ ∑ q = 1 ⌊ N d ⌋ μ ( d ) = ∑ d = 1 N μ ( d ) ⌊ N d ⌋ 3 \\begin{aligned} &\\ \\ \\ \\ \\ \\sum_{i=1}^N\\sum_{j=1}^N\\sum_{p=1}^{\\left\\lfloor\\frac N j\\right\\rfloor}\\sum_{q=1}^{\\left\\lfloor\\frac N j\\right\\rfloor}[\\gcd(i, j)=1][\\gcd(p, q)=1]&\\\\& =\\sum_{i=1}^N\\sum_{j=1}^N\\sum_{p=1}^{N}\\sum_{q=1}^{N}[\\gcd(i, j)=1][\\gcd(p, q)=j]&\\\\& =\\sum_{i=1}^N\\sum_{p=1}^{N}\\sum_{q=1}^{N}[\\gcd(i, p,q)=1]&\\\\& =\\sum_{i=1}^N\\sum_{p=1}^{N}\\sum_{q=1}^{N}\\sum_{d\\mid \\gcd(i,p,q)}\\mu(d)&\\\\& =\\sum_{d=1}^N\\sum_{i=1}^N\\sum_{p=1}^{N}\\sum_{q=1}^{N}[d\\mid i][d\\mid p][d\\mid q]\\mu(d)&\\\\& =\\sum_{d=1}^N\\sum_{i=1}^{\\left\\lfloor\\frac N d\\right\\rfloor }\\sum_{p=1}^{\\left\\lfloor\\frac N d\\right\\rfloor }\\sum_{q=1}^{\\left\\lfloor\\frac N d\\right\\rfloor}\\mu(d)&\\\\& =\\sum_{d=1}^N\\mu(d)\\left\\lfloor\\frac N d\\right\\rfloor^3 \\end{aligned}      i=1Nj=1Np=1jNq=1jN[gcd(i,j)=1][gcd(p,q)=1]=i=1Nj=1Np=1Nq=1N[gcd(i,j)=1][gcd(p,q)=j]=i=1Np=1Nq=1N[gcd(i,p,q)=1]=i=1Np=1Nq=1Ndgcd(i,p,q)μ(d)=d=1Ni=1Np=1Nq=1N[di][dp][dq]μ(d)=d=1Ni=1dNp=1d「Luogu2257」YY的GCD

[WC2013][luogu4074] 糖果公园 [树上带修改莫队]

[Luogu4074][WC2013]糖果公园

luogu1903 模板分块/带修改莫队(数颜色)

[luogu1972][bzoj1878][SDOI2009]HH的项链莫队+玄学卡常

luogu P3901 数列找不同 题解