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=1∑Nj=1∑Np=1∑⌊ȷN⌋q=1∑⌊jN⌋[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=1∑Nj=1∑Np=1∑⌊jN⌋q=1∑⌊jN⌋[gcd(i,j)=1][gcd(p,q)=1]=i=1∑Nj=1∑Np=1∑Nq=1∑N[gcd(i,j)=1][gcd(p,q)=j]=i=1∑Np=1∑Nq=1∑N[gcd(i,p,q)=1]=i=1∑Np=1∑Nq=1∑Nd∣gcd(i,p,q)∑μ(d)=d=1∑Ni=1∑Np=1∑Nq=1∑N[d∣i][d∣p][d∣q]μ(d)=d=1∑Ni=1∑⌊dN⌋p=1∑⌊d「Luogu2257」YY的GCD
[WC2013][luogu4074] 糖果公园 [树上带修改莫队]