UVA10214- 树林里的树 Trees in a Wood. - 莫比乌斯反演

Posted Chivas_/Regal

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了UVA10214- 树林里的树 Trees in a Wood. - 莫比乌斯反演相关的知识,希望对你有一定的参考价值。

题目:
在这里插入图片描述

思路:

[SDOI2008]仪仗队很像
在一个象限内
都是让求
∑ i = 1 N ∑ j = 1 M [ g c d ( i , j ) = 1 ] \\sum_{i = 1}^{N}\\sum_{j=1}^{M}[gcd(i,j)=1] i=1Nj=1M[gcd(i,j)=1]
所以我们设置 f ( n ) = ∑ i = 1 N ∑ j = 1 M [ g c d ( i , j ) = n ] , f ( 1 ) =    ? f(n) = \\sum_{i = 1}^{N}\\sum_{j=1}^{M}[gcd(i,j)=n],\\quad f(1) = \\;? f(n)=i=1Nj=1M[gcd(i,j)=n],f(1)=?
但是因为 f ( 1 ) f(1) f(1)比较难求,所以我们同时要设置一个满足 F ( n ) = ∑ n ∣ d f ( d ) F(n) = \\sum_{n|d}f(d) F(n)=ndf(d) F ( n ) F(n) F(n)
F ( n ) = ∑ i = 1 N ∑ j = 1 M [ n ∣ g c d ( i , j ) ] , F ( 1 ) = ∑ i = 1 N ∑ j = 1 M 1 F(n) = \\sum_{i = 1}^{N}\\sum_{j=1}^{M}[n | gcd(i,j)],\\quad F(1) = \\sum_{i = 1}^{N}\\sum_{j=1}^{M}1 F(n)=i=1Nj=1M[ngcd(i,j)],F(1)=i=1Nj=1M1
∴ F ( n ) = ∑ n ∣ d f ( d ) , F ( 1 ) = ∑ d = 1 m i n ( N , M ) f ( d ) \\therefore F(n) = \\sum_{n|d}f(d),\\quad F(1) = \\sum_{d = 1}^{min(N,M)}f(d) F(n)=ndf(d),F(1)=d=1min(N,M)f(d)
∴ f ( n ) = ∑ n ∣ d μ ( d n ) F ( d ) , f ( 1 ) = ∑ d = 1 m i n ( N , M ) μ ( d ) F ( d ) \\therefore f(n) = \\sum_{n|d}\\mu(\\frac dn)F(d),\\quad f(1) = \\sum_{d=1}^{min(N,M)}\\mu(d)F(d) f(n)=ndμ(nd)F(d),f(1)=d=1min(N,M)μ(d)F(d)
∵ 1 ≤ d ≤ m i n ( N , M ) \\because 1 \\le d \\le min(N, M) 1dmin(N,M)
∴ F ( d ) = ⌊ N d ⌋ ∗ ⌊ M d ⌋ \\therefore F(d) = \\left \\lfloor \\frac Nd \\right \\rfloor * \\left \\lfloor \\frac Md \\right \\rfloor F(d)=dNdM
∴ f ( 1 ) = ∑ d = 1 m i n ( N , M ) μ ( d ) ∗ ⌊ N d ⌋ ∗ ⌊ M d ⌋ \\therefore f(1) = \\sum_{d=1}^{min(N,M)}\\mu(d) * \\left \\lfloor \\frac Nd \\right \\rfloor * \\left \\lfloor \\frac Md \\right \\rfloor f(1)=d=1min(N,M)μ(d)dNdM
由于四个象限 + 四个坐标轴,所以分子为 4 ∗ ∑ d = 1 m i n ( N , M ) μ ( d ) ∗ ⌊ n d ⌋ ∗ ⌊ m d ⌋ + 4 4 * \\sum_{d = 1}^{min(N, M)}μ(d)*\\left \\lfloor \\frac nd \\right \\rfloor *\\left \\lfloor \\frac md \\right \\rfloor + 4 4d=1min(N,M)μ(d)dndm+4
分母则是所有的树 ( N ∗ 2 + 1 ) ∗ ( M ∗ 2 + 1 ) − 1 (N * 2 + 1) * (M * 2 + 1) - 1 (N2+1)(M2+1)1

答案则是 4 ∗ ∑ d = 1 m i n ( N , M ) μ ( d ) ∗ ⌊ n d ⌋ ∗ ⌊ m d ⌋ + 4 ( N ∗ 2 + 1 ) ∗ ( M ∗ 2 + 1 ) − 1 \\frac {4 * \\sum_{d = 1}^{min(N, M)}μ(d)*\\left \\lfloor \\frac nd \\right \\rfloor *\\left \\lfloor \\frac md \\right \\rfloor + 4}{(N * 2 + 1) * (M * 2 + 1) - 1} (N2+1)(M2+1)14d=1min(N,M)μ(d)dndm+4保留7位小数

代码:

/*
           ________   _                                              ________                              _
          /  ______| | |                                            |   __   |                            | |
         /  /        | |                                            |  |__|  |                            | |
         |  |        | |___    _   _   _   ___  _   _____           |     ___|   ______   _____   ___  _  | |
         |  |        |  __ \\  |_| | | | | |  _\\| | | ____|          |  |\\  \\    |  __  | |  _  | |  _\\| | | |
         |  |        | |  \\ |  _  | | | | | | \\  | | \\___           |  | \\  \\   | |_/ _| | |_| | | | \\  | | |
         \\  \\______  | |  | | | | \\ |_| / | |_/  |  ___/ |          |  |  \\  \\  |    /_   \\__  | | |_/  | | |
Author :  \\________| |_|  |_| |_|  \\___/  |___/|_| |_____| _________|__|   \\__\\ |______|     | | |___/|_| |_|
                                                                                         ____| |
                                                                                         \\_____/
*/
以上是关于UVA10214- 树林里的树 Trees in a Wood. - 莫比乌斯反演的主要内容,如果未能解决你的问题,请参考以下文章

UVa 10214 Trees in a Wood. (数论-欧拉函数)

UVa 10562 Undraw the Trees 看图写树

树的层次遍历(Trees on the level,UVA 122)

Undraw the Trees UVA - 10562

UVA10562-Undraw the Trees(递归)

使用trees包绘制带有一些松鼠的树时出错