HDU - 6715 - 算术 = 莫比乌斯反演

http://acm.hdu.edu.cn/showproblem.php?pid=6715

题意:

求:\(\sum\limits_{i=1}^{n}\sum\limits_{j=1}^{m}\mu(lcm(i,j))\),其中n,m是1e6范围内,10组。

不会,想了很久,也不知道假在哪里。大概是一开始方向就错了。


正解:

所求:\(\sum\limits_{i=1}^{n}\sum\limits_{j=1}^{m}\mu(lcm(i,j))\)

即:\(\sum\limits_{i=1}^{n}\sum\limits_{j=1}^{m}\mu(\frac{i*j}{gcd(i,j)})\)

枚举g:\(\sum\limits_{g=1}^{N}\sum\limits_{i=1}^{n}\sum\limits_{j=1}^{m}\mu(\frac{i*j}{g})*[gcd(i,j)==g]\)

由一个显然的事实:\(\mu(xy)=\mu(x)*\mu(y)*[gcd(x,y)==1]\)

代进去:\(\mu(\frac{i}{g}*j)=\mu(\frac{i}{g})*\mu(j)*[gcd(\frac{i}{g},j)==1]\) 后面那项显然为1

即:\(\sum\limits_{g=1}^{N}\sum\limits_{i=1}^{n}\sum\limits_{j=1}^{m}\mu(\frac{i}{g})*\mu(j)*[gcd(\frac{i}{g},j)==1]*[gcd(i,j)==g]\)

同理:\(\mu(j)=\mu(\frac{j}{g}*g)=\mu(\frac{j}{g})*\mu(g)*[gcd(\frac{j}{g},g)==1]\)

即:\(\sum\limits_{g=1}^{N}\sum\limits_{i=1}^{n}\sum\limits_{j=1}^{m}\mu(\frac{i}{g})*\mu(\frac{j}{g})*\mu(g)*[gcd(\frac{j}{g},g)==1]*[gcd(i,j)==g]\)

即:\(\sum\limits_{g=1}^{N}\mu(g)\sum\limits_{i=1}^{n}\mu(\frac{i}{g})\sum\limits_{j=1}^{m}\mu(\frac{j}{g})*[gcd(\frac{j}{g},g)==1]*[gcd(i,j)==g]\)

即:\(\sum\limits_{g=1}^{N}\mu(g)\sum\limits_{i=1}^{\frac{n}{g}}\mu(i)\sum\limits_{j=1}^{\frac{m}{g}}\mu(j)*[gcd(j,g)==1]*[gcd(i,j)==1]\)

即:\(\sum\limits_{g=1}^{N}\mu(g)\sum\limits_{i=1}^{\frac{n}{g}}\mu(i)\sum\limits_{j=1}^{\frac{m}{g}}\mu(j)*[gcd(gcd(i,j),g)==1]\)

莫比乌斯反演:\(\sum\limits_{g=1}^{N}\mu(g)\sum\limits_{i=1}^{\frac{n}{g}}\mu(i)\sum\limits_{j=1}^{\frac{m}{g}}\mu(j)\sum\limits_{k|gcd(gcd(i,j),g)}\mu(k)\)

即:\(\sum\limits_{k=1}^{N}\mu(k)\sum\limits_{g=1}^{N}\mu(g)\sum\limits_{i=1}^{\frac{n}{g}}\mu(i)\sum\limits_{j=1}^{\frac{m}{g}}\mu(j)*[k|i]*[k|j]*[k|g]\)

一般是像上面那样变的,但是这里我们要把k放进去:\(\sum\limits_{k=1}^{N}\mu(k)\sum\limits_{g=1}^{\frac{N}{k}}\mu(gk)\sum\limits_{i=1}^{\frac{n}{gk}}\mu(ik)\sum\limits_{j=1}^{\frac{m}{gk}}\mu(jk)\)

为了简单,记:\(S(N,k)=\sum\limits_{i=1}^{\frac{N}{k}}\mu(ik)\)

那么上式就变成:\(\sum\limits_{k=1}^{N}\mu(k)\sum\limits_{g=1}^{\frac{N}{k}}\mu(gk)*S(\frac{n}{g},k)*S(\frac{m}{g},k)\)

那么枚举k,然后预处理S(N,k),再暴力算就可以了。

原文地址:https://www.cnblogs.com/Inko/p/11407474.html

时间: 2024-10-13 11:11:46

HDU - 6715 - 算术 = 莫比乌斯反演的相关文章

HDU 4746 Mophues (莫比乌斯反演应用)

Mophues Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 327670/327670 K (Java/Others) Total Submission(s): 980    Accepted Submission(s): 376 Problem Description As we know, any positive integer C ( C >= 2 ) can be written as the multiply of

hdu.5212.Code(莫比乌斯反演 && 线性筛)

Code Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 300    Accepted Submission(s): 124 Problem Description WLD likes playing with codes.One day he is writing a function.Howerver,his computer b

HDU 5072 Coprime (莫比乌斯反演+容斥+同色三角形)

Coprime Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 1469    Accepted Submission(s): 579 Problem Description There are n people standing in a line. Each of them has a unique id number. Now

HDU 4746 Mophues 莫比乌斯反演

分析: http://blog.csdn.net/acdreamers/article/details/12871643 分析参见这一篇 http://wenku.baidu.com/view/fbe263d384254b35eefd34eb.html 分块看这一篇 #include<cstdio> #include<cstring> #include<queue> #include<cstdlib> #include<algorithm> #i

[HDU 5072] Coprime 莫比乌斯反演

题意 ? 给定一个长度为 $n$ 的序列 $A = \left\{ a_1, a_2, ..., a_n \right\}$ . ? 问有多少个三元组 $(i, j, k)(i \ne j, i \ne k, j \ne k)$ , 满足 $\left\{ \begin{aligned} & a_i \perp a_j \\ & a_i \perp a_k \\ & a_j \perp a_k \end{aligned} \right.$ 或 $\left\{ \begin{ali

HDU - 4746预处理莫比乌斯反演

链接 求[1,n] 和 [1,m]中有多少对数的GCD的素因子个数小于等于p 直接暴力做特定超时,所以我们想办法预处理,对于p大于18(1到5e5的最大素数因子个数)的情况,每一对都满足条件,O(1)得结果. p<=18时,预处理sum[i][j]sum[i][j]表示所有能整除i的质因子个数<=j的(x,y)的对数,然后求一个前缀和,ans=∑⌊n/d⌋∗⌊m/d⌋∗∑k|dμ(d/k) //#pragma comment(linker, "/stack:200000000&quo

hdu 1695 莫比乌斯反演

hdu 1695 莫比乌斯反演 题意: 给出a,b,c,d,k, 求满足a <= x <= b && c <= y <= d && gcd(x,y)=k 的数对(x,y)的对数. 限制: a=c=1; 0 < b,c <= 1e5; (n1,n2) 和 (n2,n1) 算为同种情况 思路: 其实是求满足1 <= x <= b/k && 1 <= y <= d/k && gcd(x,y

hdu 1695 容斥原理或莫比乌斯反演

GCD Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 5310    Accepted Submission(s): 1907 Problem Description Given 5 integers: a, b, c, d, k, you're to find x in a...b, y in c...d that GCD(x, y)

E - GuGuFishtion HDU - 6390(欧拉函数 / 莫比乌斯反演)

GuGuFishtion (HDU - 6390) 题意: 定义\(G_u (a,b)=\frac{\phi(ab)}{\phi(a)\phi(b)}\). 求\((\sum\limits_{a=1}^m\sum\limits_{b=1}^nG_u (a,b))\pmod p\). 题解: 考虑\(\phi(x) = x*(1-\frac{1}{p_1})*(1-\frac{1}{p_2})...*(1-\frac{1}{p_n})\). 将\(G_u (a,b)\)的分子与分母按上述分解.约分