【luogu P5518】[MtOI2019]幽灵乐团 / 莫比乌斯反演基础练习题(莫比乌斯反演)

[MtOI2019]幽灵乐团 / 莫比乌斯反演基础练习题

题目链接:luogu P5518

题目大意

∏ i = 1 A ∏ j = 1 B ∏ k = 1 C ( lcm ( i , j ) gcd ⁡ ( i , k ) ) f ( t y p e ) \prod\limits_{i=1}^{A}\prod\limits_{j=1}^{B}\prod\limits_{k=1}^{C}(\dfrac{\text{lcm}(i,j)}{\gcd(i,k)})^{f(type)} i=1Aj=1Bk=1C(gcd(i,k)lcm(i,j))f(type)
多组数据,要你在 f ( t y p e ) f(type) f(type) 分别是 1 , i × j × k , gcd ⁡ ( i , j , k ) 1,i\times j\times k,\gcd(i,j,k) 1,i×j×k,gcd(i,j,k) 的时候求式子的值。

思路

主要的思想是对于每个部分你就求两个东西:
∏ i = 1 A ∏ j = 1 B ∏ k = 1 C i f ( t y p e ) \prod\limits_{i=1}^{A}\prod\limits_{j=1}^{B}\prod\limits_{k=1}^{C}i^{f(type)} i=1Aj=1Bk=1Cif(type)
∏ i = 1 A ∏ j = 1 B ∏ k = 1 C gcd ⁡ ( i , j ) f ( t y p e ) \prod\limits_{i=1}^{A}\prod\limits_{j=1}^{B}\prod\limits_{k=1}^{C}\gcd(i,j)^{f(type)} i=1Aj=1Bk=1Cgcd(i,j)f(type)

不多说了直接看我推导过程吧!
∏ i = 1 A ∏ j = 1 B ∏ k = 1 C ( lcm ( i , j ) gcd ⁡ ( i , k ) ) f ( t y p e ) \prod\limits_{i=1}^{A}\prod\limits_{j=1}^{B}\prod\limits_{k=1}^{C}(\dfrac{\text{lcm}(i,j)}{\gcd(i,k)})^{f(type)} i=1Aj=1Bk=1C(gcd(i,k)lcm(i,j))f(type)


∏ i = 1 n ∏ j = 1 m gcd ⁡ ( i , j ) \prod\limits_{i=1}^n\prod\limits_{j=1}^m\gcd(i,j) i=1nj=1mgcd(i,j)
∏ d d ∑ i = 1 n ∑ j = 1 m [ gcd ⁡ ( i , j ) = = d ] \prod\limits_{d}d^{\sum\limits_{i=1}^n\sum\limits_{j=1}^m[\gcd(i,j)==d]} ddi=1nj=1m[gcd(i,j)==d]

O ( n log ⁡ n ) O(n\log n) O(nlogn)


t y p e = 1 type=1 type=1
∏ i = 1 A ∏ j = 1 B ∏ k = 1 C lcm ( i , j ) gcd ⁡ ( i , k ) \prod\limits_{i=1}^{A}\prod\limits_{j=1}^{B}\prod\limits_{k=1}^{C}\dfrac{\text{lcm}(i,j)}{\gcd(i,k)} i=1Aj=1Bk=1Cgcd(i,k)lcm(i,j)
∏ i = 1 A ∏ j = 1 B ∏ k = 1 C 1 gcd ⁡ ( i , k ) ∏ i = 1 A ∏ j = 1 B ∏ k = 1 C lcm ( i , j ) \prod\limits_{i=1}^{A}\prod\limits_{j=1}^{B}\prod\limits_{k=1}^{C}\dfrac{1}{\gcd(i,k)}\prod\limits_{i=1}^{A}\prod\limits_{j=1}^{B}\prod\limits_{k=1}^{C}\text{lcm}(i,j) i=1Aj=1Bk=1Cgcd(i,k)1i=1Aj=1Bk=1Clcm(i,j)
( ∏ i = 1 A ∏ k = 1 C 1 gcd ⁡ ( i , k ) ) B ( ∏ i = 1 A ∏ j = 1 B lcm ( i , j ) ) C (\prod\limits_{i=1}^{A}\prod\limits_{k=1}^{C}\dfrac{1}{\gcd(i,k)})^B(\prod\limits_{i=1}^{A}\prod\limits_{j=1}^{B}\text{lcm}(i,j))^C (i=1Ak=1Cgcd(i,k)1)B(i=1Aj=1Blcm(i,j))C
( ∏ i = 1 A ∏ k = 1 C 1 gcd ⁡ ( i , k ) ) B ( ∏ i = 1 A ∏ j = 1 B i j gcd ⁡ ( i , j ) ) C (\prod\limits_{i=1}^{A}\prod\limits_{k=1}^{C}\dfrac{1}{\gcd(i,k)})^B(\prod\limits_{i=1}^{A}\prod\limits_{j=1}^{B}\dfrac{ij}{\gcd(i,j)})^C (i=1Ak=1Cgcd(i,k)1)B(i=1Aj=1Bgcd(i,j)ij)C
( ∏ i = 1 A ∏ k = 1 C 1 gcd ⁡ ( i , k ) ) B ( ∏ i = 1 A ∏ j = 1 B 1 gcd ⁡ ( i , j ) ) C ( ∏ i = 1 A ∏ j = 1 B i j ) C (\prod\limits_{i=1}^{A}\prod\limits_{k=1}^{C}\dfrac{1}{\gcd(i,k)})^B(\prod\limits_{i=1}^{A}\prod\limits_{j=1}^{B}\dfrac{1}{\gcd(i,j)})^C(\prod\limits_{i=1}^{A}\prod\limits_{j=1}^{B}ij)^C (i=1Ak=1Cgcd(i,k)1)B(i=1Aj=1Bgcd(i,j)1)C(i=1Aj=1Bij)C
( ∏ i = 1 A ∏ k = 1 C 1 gcd ⁡ ( i , k ) ) B ( ∏ i = 1 A ∏ j = 1 B 1 gcd ⁡ ( i , j ) ) C ( ( A ! ) B ( B ! ) A ) C (\prod\limits_{i=1}^{A}\prod\limits_{k=1}^{C}\dfrac{1}{\gcd(i,k)})^B(\prod\limits_{i=1}^{A}\prod\limits_{j=1}^{B}\dfrac{1}{\gcd(i,j)})^C((A!)^B(B!)^A )^C (i=1Ak=1Cgcd(i,k)1)B(i=1Aj=1Bgcd(i,j)1)C((A!)B(B!)A)C


∏ i = 1 A ∏ j = 1 B gcd ⁡ ( i , j ) i j \prod\limits_{i=1}^{A}\prod\limits_{j=1}^{B}\gcd(i,j)^{ij} i=1Aj=1Bgcd(i,j)ij
∏ d d ∑ i = 1 A ∑ j = 1 B [ gcd ⁡ ( i , j ) = = d ] ( i j ) \prod\limits_{d}d^{\sum\limits_{i=1}^{A}\sum\limits_{j=1}^{B}[\gcd(i,j)==d](ij)} ddi=1Aj=1B[gcd(i,j)==d](ij)
∏ d d ∑ i = 1 ⌊ A d ⌋ ∑ j = 1 ⌊ B d ⌋ [ gcd ⁡ ( i , j ) = = 1 ] ( i d j d ) \prod\limits_{d}d^{\sum\limits_{i=1}^{\left\lfloor\frac{A}{d}\right\rfloor}\sum\limits_{j=1}^{\left\lfloor\frac{B}{d}\right\rfloor}[\gcd(i,j)==1](idjd)} ddi=1dAj=1dB[gcd(i,j)==1](idjd)
∏ d d d 2 d ′ 2 ∑ d ′ μ ( d ′ ) ∑ i = 1 ⌊ A d d ′ ⌋ ∑ j = 1 ⌊ B d d ′ ⌋ ( i j ) \prod\limits_{d}d^{d^2d'^2\sum\limits_{d'}\mu(d')\sum\limits_{i=1}^{\left\lfloor\frac{A}{dd'}\right\rfloor}\sum\limits_{j=1}^{\left\lfloor\frac{B}{dd'}\right\rfloor}(ij)} ddd2d2dμ(d)i=1ddAj=1ddB(ij)
∏ d d d 2 d ′ 2 ∑ d ′ μ ( d ′ ) ∑ i = 1 ⌊ A d d ′ ⌋ i ∑ j = 1 ⌊ B d d ′ ⌋ j \prod\limits_{d}d^{d^2d'^2\sum\limits_{d'}\mu(d')\sum\limits_{i=1}^{\left\lfloor\frac{A}{dd'}\right\rfloor}i\sum\limits_{j=1}^{\left\lfloor\frac{B}{dd'}\right\rfloor}j} ddd2d2dμ(d)i=1ddAij=1ddBj
∏ D ( ∏ d ∣ D d μ ( ⌊ D d ⌋ ) ) D 2 ∑ i = 1 ⌊ A D ⌋ i ∑ j = 1 ⌊ B D ⌋ j \prod\limits_{D}(\prod\limits_{d|D}d^{\mu(\left\lfloor\frac{D}{d}\right\rfloor)})^{D^2\sum\limits_{i=1}^{\left\lfloor\frac{A}{D}\right\rfloor}i\sum\limits_{j=1}^{\left\lfloor\frac{B}{D}\right\rfloor}j} D(dDdμ(dD))D2i=1DAij=1DBj

<—>
∏ i = 1 A ∏ j = 1 B ∏ k = 1 C gcd ⁡ ( i , j ) i j k \prod\limits_{i=1}^{A}\prod\limits_{j=1}^{B}\prod\limits_{k=1}^{C}\gcd(i,j)^{ijk} i=1Aj=1Bk=1Cgcd(i,j)ijk
∏ k = 1 C ( ∏ i = 1 A ∏ j = 1 B gcd ⁡ ( i , j ) i j ) k \prod\limits_{k=1}^{C}(\prod\limits_{i=1}^{A}\prod\limits_{j=1}^{B}\gcd(i,j)^{ij})^k k=1C(i=1Aj=1Bgcd(i,j)ij)k
( ∏ i = 1 A ∏ j = 1 B gcd ⁡ ( i , j ) i j ) ∑ k = 1 C k (\prod\limits_{i=1}^{A}\prod\limits_{j=1}^{B}\gcd(i,j)^{ij})^{\sum\limits_{k=1}^{C}k} (i=1Aj=1Bgcd(i,j)ij)k=1Ck


∏ i = 1 A ∏ j = 1 B ∏ k = 1 C i i j k \prod\limits_{i=1}^{A}\prod\limits_{j=1}^{B}\prod\limits_{k=1}^{C}i^{ijk} i=1Aj=1Bk=1Ciijk
∏ i = 1 A i i ∑ j = 1 B ∑ k = 1 C j k \prod\limits_{i=1}^{A}i^{i\sum\limits_{j=1}^B\sum\limits_{k=1}^Cjk} i=1Aiij=1Bk=1Cjk
∏ i = 1 A i i ( ∑ j = 1 B j ) ( ∑ k = 1 C k ) \prod\limits_{i=1}^{A}i^{i(\sum\limits_{j=1}^Bj)(\sum\limits_{k=1}^Ck)} i=1Aii(j=1Bj)(k=1Ck)


t y p e = 1 type=1 type=1
∏ i = 1 A ∏ j = 1 B ∏ k = 1 C ( lcm ( i , j ) gcd ⁡ ( i , k ) ) i j k \prod\limits_{i=1}^{A}\prod\limits_{j=1}^{B}\prod\limits_{k=1}^{C}(\dfrac{\text{lcm}(i,j)}{\gcd(i,k)})^{ijk} i=1Aj=1Bk=1C(gcd(i,k)lcm(i,j))ijk
∏ i = 1 A ∏ j = 1 B ∏ k = 1 C 1 gcd ⁡ ( i , k ) i j k ∏ i = 1 A ∏ j = 1 B ∏ k = 1 C lcm ( i , j ) i j k \prod\limits_{i=1}^{A}\prod\limits_{j=1}^{B}\prod\limits_{k=1}^{C}\dfrac{1}{\gcd(i,k)^{ijk}}\prod\limits_{i=1}^{A}\prod\limits_{j=1}^{B}\prod\limits_{k=1}^{C}\text{lcm}(i,j)^{ijk} i=1Aj=1Bk=1Cgcd(i,k)ijk1i=1Aj=1Bk=1Clcm(i,j)ijk
∏ i = 1 A ∏ j = 1 B ∏ k = 1 C 1 gcd ⁡ ( i , k ) i j k ∏ i = 1 A ∏ j = 1 B ∏ k = 1 C ( i j gcd ⁡ ( i , j ) ) i j k \prod\limits_{i=1}^{A}\prod\limits_{j=1}^{B}\prod\limits_{k=1}^{C}\dfrac{1}{\gcd(i,k)^{ijk}}\prod\limits_{i=1}^{A}\prod\limits_{j=1}^{B}\prod\limits_{k=1}^{C}(\dfrac{ij}{\gcd(i,j)})^{ijk} i=1Aj=1Bk=1Cgcd(i,k)ijk1i=1Aj=1Bk=1C(gcd(i,j)ij)ijk


t y p e = 2 type=2 type=2

∏ i = 1 A ∏ j = 1 B ∏ k = 1 C i gcd ⁡ ( i , j , k ) \prod\limits_{i=1}^{A}\prod\limits_{j=1}^{B}\prod\limits_{k=1}^{C}i^{\gcd(i,j,k)} i=1Aj=1Bk=1Cigcd(i,j,k)
∏ d ∏ i = 1 A i d ∑ j = 1 B ∑ k = 1 C [ gcd ⁡ ( i , j , k ) = = d ] \prod\limits_{d}\prod\limits_{i=1}^{A}i^{d\sum\limits_{j=1}^{B}\sum\limits_{k=1}^{C}[\gcd(i,j,k)==d]} di=1Aidj=1Bk=1C[gcd(i,j,k)==d]
∏ d ∏ i = 1 ⌊ A d ⌋ ( i d ) d ∑ j = 1 ⌊ B d ⌋ ∑ k = 1 ⌊ C d ⌋ [ gcd ⁡ ( i , j , k ) = = 1 ] \prod\limits_{d}\prod\limits_{i=1}^{\left\lfloor \frac{A}{d}\right\rfloor}(id)^{d\sum\limits_{j=1}^{\left\lfloor \frac{B}{d}\right\rfloor}\sum\limits_{k=1}^{\left\lfloor \frac{C}{d}\right\rfloor}[\gcd(i,j,k)==1]} di=1dA(id)dj=1dBk=1dC[gcd(i,j,k)==1]
∏ d ∏ i = 1 ⌊ A d ⌋ ( i d ) d ∑ j = 1 ⌊ B d ⌋ ∑ k = 1 ⌊ C d ⌋ [ gcd ⁡ ( i , j , k ) = = 1 ] \prod\limits_{d}\prod\limits_{i=1}^{\left\lfloor \frac{A}{d}\right\rfloor}(id)^{d\sum\limits_{j=1}^{\left\lfloor \frac{B}{d}\right\rfloor}\sum\limits_{k=1}^{\left\lfloor \frac{C}{d}\right\rfloor}[\gcd(i,j,k)==1]} di=1dA(id)dj=1dBk=1dC[gcd(i,j,k)==1]
∏ d ∏ d ′ ∏ i = 1 ⌊ A d d ′ ⌋ ( i d d ′ ) d μ ( d ′ ) ⌊ B d d ′ ⌋ ⌊ C d d ′ ⌋ \prod\limits_{d}\prod\limits_{d'}\prod\limits_{i=1}^{\left\lfloor \frac{A}{dd'}\right\rfloor}(idd')^{d\mu(d')\left\lfloor \frac{B}{dd'}\right\rfloor\left\lfloor \frac{C}{dd'}\right\rfloor} ddi=1ddA(idd)dμ(d)ddBddC
∏ D ( ∏ d ∣ D ∏ i = 1 ⌊ A D ⌋ ( i D ) d μ ( ⌊ D d ⌋ ) ) ⌊ B D ⌋ ⌊ C D ⌋ \prod\limits_{D}(\prod\limits_{d|D}\prod\limits_{i=1}^{\left\lfloor \frac{A}{D}\right\rfloor}(iD)^{d\mu(\left\lfloor\frac{D}{d}\right\rfloor)})^{\left\lfloor \frac{B}{D}\right\rfloor\left\lfloor \frac{C}{D}\right\rfloor} D(dDi=1DA(iD)dμ(dD))DBDC
∏ D ( ∏ d ∣ D ( ∏ i = 1 ⌊ A D ⌋ ( i ) d μ ( ⌊ D d ⌋ ) ) ( D d μ ( ⌊ D d ⌋ ) ⌊ A D ⌋ ) ) ⌊ B D ⌋ ⌊ C D ⌋ \prod\limits_{D}(\prod\limits_{d|D}(\prod\limits_{i=1}^{\left\lfloor \frac{A}{D}\right\rfloor}(i)^{d\mu(\left\lfloor\frac{D}{d}\right\rfloor)})(D^{d\mu(\left\lfloor\frac{D}{d}\right\rfloor)\left\lfloor\frac{A}{D}\right\rfloor}))^{\left\lfloor \frac{B}{D}\right\rfloor\left\lfloor \frac{C}{D}\right\rfloor} D(dD(i=1DA(i)dμ(dD))(Ddμ(dD)DA))DBDC
∏ D ( ∏ d ∣ D ( ⌊ A D ⌋ ) ! d μ ( ⌊ D d ⌋ ) D d μ ( ⌊ D d ⌋ ) ⌊ A D ⌋ ) ⌊ B D ⌋ ⌊ C D ⌋ \prod\limits_{D}\left(\prod\limits_{d|D}(\left\lfloor \frac{A}{D}\right\rfloor)!^{d\mu(\left\lfloor\frac{D}{d}\right\rfloor)}D^{d\mu(\left\lfloor\frac{D}{d}\right\rfloor)\left\lfloor\frac{A}{D}\right\rfloor}\right)^{\left\lfloor \frac{B}{D}\right\rfloor\left\lfloor \frac{C}{D}\right\rfloor} D(dD(DA)!dμ(dD)Ddμ(dD)DA)DBDC
∏ D ( ∏ d ∣ D ( ( ⌊ A D ⌋ ) ! D ⌊ A D ⌋ ) d μ ( ⌊ D d ⌋ ) ) ⌊ B D ⌋ ⌊ C D ⌋ \prod\limits_{D}\left(\prod\limits_{d|D}\left( (\left\lfloor \frac{A}{D}\right\rfloor)!D^{\left\lfloor\frac{A}{D}\right\rfloor}\right)^{d\mu(\left\lfloor\frac{D}{d}\right\rfloor)} \right)^{\left\lfloor \frac{B}{D}\right\rfloor\left\lfloor \frac{C}{D}\right\rfloor} D(dD((DA)!DDA)dμ(dD))DBDC
∏ D ( ( ( ⌊ A D ⌋ ) ! D ⌊ A D ⌋ ) ∑ d ∣ D d μ ( ⌊ D d ⌋ ) ) ⌊ B D ⌋ ⌊ C D ⌋ \prod\limits_{D}\left(\left( (\left\lfloor \frac{A}{D}\right\rfloor)!D^{\left\lfloor\frac{A}{D}\right\rfloor}\right)^{\sum\limits_{d|D}d\mu(\left\lfloor\frac{D}{d}\right\rfloor)} \right)^{\left\lfloor \frac{B}{D}\right\rfloor\left\lfloor \frac{C}{D}\right\rfloor} D(((DA)!DDA)dDdμ(dD))DBDC
∏ D ( ( ( ⌊ A D ⌋ ) ! D ⌊ A D ⌋ ) φ ( D ) ) ⌊ B D ⌋ ⌊ C D ⌋ \prod\limits_{D}\left(\left( (\left\lfloor \frac{A}{D}\right\rfloor)!D^{\left\lfloor\frac{A}{D}\right\rfloor}\right)^{\varphi(D)} \right)^{\left\lfloor \frac{B}{D}\right\rfloor\left\lfloor \frac{C}{D}\right\rfloor} D(((DA)!DDA)φ(D))DBDC
∏ D ( ( ⌊ A D ⌋ ) ! φ ( D ) ( D φ ( D ) ) ⌊ A D ⌋ ) ⌊ B D ⌋ ⌊ C D ⌋ \prod\limits_{D}\left((\left\lfloor \frac{A}{D}\right\rfloor)!^{\varphi(D)}\left(D^{\varphi(D)}\right)^{\left\lfloor\frac{A}{D}\right\rfloor} \right)^{\left\lfloor \frac{B}{D}\right\rfloor\left\lfloor \frac{C}{D}\right\rfloor} D((DA)!φ(D)(Dφ(D))DA)DBDC
( ∏ D ( ⌊ A D ⌋ ) ! φ ( D ) ) ⌊ B D ⌋ ⌊ C D ⌋ ( ∏ D ( D φ ( D ) ) ) ⌊ A D ⌋ ⌊ B D ⌋ ⌊ C D ⌋ \left(\prod\limits_{D}(\left\lfloor \frac{A}{D}\right\rfloor)!^{\varphi(D)}\right)^{\left\lfloor \frac{B}{D}\right\rfloor\left\lfloor \frac{C}{D}\right\rfloor}\left(\prod\limits_{D}\left(D^{\varphi(D)}\right) \right)^{\left\lfloor\frac{A}{D}\right\rfloor\left\lfloor \frac{B}{D}\right\rfloor\left\lfloor \frac{C}{D}\right\rfloor} (D(DA)!φ(D))DBDC(D(Dφ(D)))DADBDC
这里右边可以预处理来做。(不过后面我们可以消掉这个部分)


t y p e = 2 type=2 type=2
∏ i = 1 A ∏ j = 1 B ∏ k = 1 C gcd ⁡ ( i , j ) gcd ⁡ ( i , j , k ) \prod\limits_{i=1}^{A}\prod\limits_{j=1}^{B}\prod\limits_{k=1}^{C}\gcd(i,j)^{\gcd(i,j,k)} i=1Aj=1Bk=1Cgcd(i,j)gcd(i,j,k)
∏ d d ( ∑ k = 1 C gcd ⁡ ( d , k ) ) ( ∑ i = 1 A ∑ j = 1 B [ gcd ⁡ ( i , j ) = = d ] ) \prod\limits_{d}d^{(\sum\limits_{k=1}^{C}\gcd(d,k))(\sum\limits_{i=1}^{A}\sum\limits_{j=1}^{B}[\gcd(i,j)==d])} dd(k=1Cgcd(d,k))(i=1Aj=1B[gcd(i,j)==d])
∏ d d ( ∑ k = 1 C gcd ⁡ ( d , k ) ) ( ∑ i = 1 ⌊ A d ⌋ ∑ j = 1 ⌊ B d ⌋ [ gcd ⁡ ( i , j ) = = 1 ] ) \prod\limits_{d}d^{(\sum\limits_{k=1}^{C}\gcd(d,k))(\sum\limits_{i=1}^{\left\lfloor \frac{A}{d}\right\rfloor}\sum\limits_{j=1}^{\left\lfloor \frac{B}{d}\right\rfloor}[\gcd(i,j)==1])} dd(k=1Cgcd(d,k))(i=1dAj=1dB[gcd(i,j)==1])
∏ d d ( ∑ k = 1 C gcd ⁡ ( d , k ) ) ( ∑ d ′ μ ( d ′ ) ⌊ A d d ′ ⌋ ⌊ B d d ′ ⌋ ) \prod\limits_{d}d^{(\sum\limits_{k=1}^{C}\gcd(d,k))(\sum\limits_{d'}\mu(d')\left\lfloor \frac{A}{dd'}\right\rfloor\left\lfloor \frac{B}{dd'}\right\rfloor)} dd(k=1Cgcd(d,k))(dμ(d)ddAddB)
∏ D ( ∏ d ∣ D d μ ( D d ) ( ∑ k = 1 C gcd ⁡ ( d , k ) ) ) ⌊ A D ⌋ ⌊ B D ⌋ \prod\limits_{D}\left(\prod\limits_{d|D}d^{\mu(\frac{D}{d})(\sum\limits_{k=1}^{C}\gcd(d,k))}\right)^{\left\lfloor \frac{A}{D}\right\rfloor\left\lfloor \frac{B}{D}\right\rfloor} DdDdμ(dD)(k=1Cgcd(d,k))DADB
O ( T n log ⁡ n ) O(Tn\log n) O(Tnlogn) 不太行常数大。

∏ i = 1 A ∏ j = 1 B ∏ k = 1 C gcd ⁡ ( i , j ) gcd ⁡ ( i , j , k ) \prod\limits_{i=1}^{A}\prod\limits_{j=1}^{B}\prod\limits_{k=1}^{C}\gcd(i,j)^{\gcd(i,j,k)} i=1Aj=1Bk=1Cgcd(i,j)gcd(i,j,k)
∏ d ∏ i = 1 A ∏ j = 1 B gcd ⁡ ( i , j ) d ( ∑ k = 1 C [ gcd ⁡ ( i , j , k ) = = d ] ) \prod\limits_{d}\prod\limits_{i=1}^{A}\prod\limits_{j=1}^{B}\gcd(i,j)^{d(\sum\limits_{k=1}^{C}[\gcd(i,j,k)==d])} di=1Aj=1Bgcd(i,j)d(k=1C[gcd(i,j,k)==d])
∏ d ∏ i = 1 ⌊ A d ⌋ ∏ j = 1 ⌊ B d ⌋ ( d gcd ⁡ ( i , j ) ) d ( ∑ k = 1 ⌊ C d ⌋ [ gcd ⁡ ( i , j , k ) = = 1 ] ) \prod\limits_{d}\prod\limits_{i=1}^{\left\lfloor \frac{A}{d}\right\rfloor}\prod\limits_{j=1}^{\left\lfloor \frac{B}{d}\right\rfloor}(d\gcd(i,j))^{d(\sum\limits_{k=1}^{\left\lfloor \frac{C}{d}\right\rfloor}[\gcd(i,j,k)==1])} di=1dAj=1dB(dgcd(i,j))d(k=1dC[gcd(i,j,k)==1])
∏ d ∏ i = 1 ⌊ A d ⌋ ∏ j = 1 ⌊ B d ⌋ ( d gcd ⁡ ( i , j ) ) d ( ∑ k = 1 ⌊ C d ⌋ [ gcd ⁡ ( i , j , k ) = = 1 ] ) \prod\limits_{d}\prod\limits_{i=1}^{\left\lfloor \frac{A}{d}\right\rfloor}\prod\limits_{j=1}^{\left\lfloor \frac{B}{d}\right\rfloor}(d\gcd(i,j))^{d(\sum\limits_{k=1}^{\left\lfloor \frac{C}{d}\right\rfloor}[\gcd(i,j,k)==1])} di=1dAj=1dB(dgcd(i,j))d(k=1dC[gcd(i,j,k)==1])
∏ d ∏ d ′ ∏ i = 1 ⌊ A d d ′ ⌋ ∏ j = 1 ⌊ B d d ′ ⌋ ( d d ′ gcd ⁡ ( i , j ) ) d μ ( d ′ ) ⌊ C d d ′ ⌋ \prod\limits_{d}\prod\limits_{d'}\prod\limits_{i=1}^{\left\lfloor \frac{A}{dd'}\right\rfloor}\prod\limits_{j=1}^{\left\lfloor \frac{B}{dd'}\right\rfloor}(dd'\gcd(i,j))^{d\mu(d')\left\lfloor \frac{C}{dd'}\right\rfloor} ddi=1ddAj=1ddB(ddgcd(i,j))dμ(d)ddC
( ∏ d ∏ d ′ ∏ i = 1 ⌊ A d d ′ ⌋ ∏ j = 1 ⌊ B d d ′ ⌋ gcd ⁡ ( i , j ) d μ ( d ′ ) ⌊ C d d ′ ⌋ ) ( ∏ d ∏ d ′ d d ′ d μ ( d ′ ) ⌊ A d d ′ ⌋ ⌊ B d d ′ ⌋ ⌊ C d d ′ ⌋ ) (\prod\limits_{d}\prod\limits_{d'}\prod\limits_{i=1}^{\left\lfloor \frac{A}{dd'}\right\rfloor}\prod\limits_{j=1}^{\left\lfloor \frac{B}{dd'}\right\rfloor}\gcd(i,j)^{d\mu(d')\left\lfloor \frac{C}{dd'}\right\rfloor})(\prod\limits_{d}\prod\limits_{d'}dd'^{d\mu(d')\left\lfloor \frac{A}{dd'}\right\rfloor\left\lfloor \frac{B}{dd'}\right\rfloor\left\lfloor \frac{C}{dd'}\right\rfloor}) (ddi=1ddAj=1ddBgcd(i,j)dμ(d)ddC)(dddddμ(d)ddAddBddC)
( ∏ d ∏ d ′ ∏ i = 1 ⌊ A d d ′ ⌋ ∏ j = 1 ⌊ B d d ′ ⌋ gcd ⁡ ( i , j ) d μ ( d ′ ) ⌊ C d d ′ ⌋ ) ( ∏ D ∏ d ∣ D D d μ ( ⌊ D d ⌋ ) ⌊ A D ⌋ ⌊ B D ⌋ ⌊ C D ⌋ ) (\prod\limits_{d}\prod\limits_{d'}\prod\limits_{i=1}^{\left\lfloor \frac{A}{dd'}\right\rfloor}\prod\limits_{j=1}^{\left\lfloor \frac{B}{dd'}\right\rfloor}\gcd(i,j)^{d\mu(d')\left\lfloor \frac{C}{dd'}\right\rfloor})(\prod\limits_{D}\prod\limits_{d|D}D^{d\mu(\left\lfloor\frac{D}{d}\right\rfloor)\left\lfloor \frac{A}{D}\right\rfloor\left\lfloor \frac{B}{D}\right\rfloor\left\lfloor \frac{C}{D}\right\rfloor}) (ddi=1ddAj=1ddBgcd(i,j)dμ(d)ddC)(DdDDdμ(dD)DADBDC)
( ∏ d ∏ d ′ ∏ i = 1 ⌊ A d d ′ ⌋ ∏ j = 1 ⌊ B d d ′ ⌋ gcd ⁡ ( i , j ) d μ ( d ′ ) ⌊ C d d ′ ⌋ ) ( ∏ D ( D φ ( D ) ) ⌊ A D ⌋ ⌊ B D ⌋ ⌊ C D ⌋ ) (\prod\limits_{d}\prod\limits_{d'}\prod\limits_{i=1}^{\left\lfloor \frac{A}{dd'}\right\rfloor}\prod\limits_{j=1}^{\left\lfloor \frac{B}{dd'}\right\rfloor}\gcd(i,j)^{d\mu(d')\left\lfloor \frac{C}{dd'}\right\rfloor})(\prod\limits_{D}(D^{\varphi(D)})^{\left\lfloor \frac{A}{D}\right\rfloor\left\lfloor \frac{B}{D}\right\rfloor\left\lfloor \frac{C}{D}\right\rfloor}) (ddi=1ddAj=1ddBgcd(i,j)dμ(d)ddC)(D(Dφ(D))DADBDC)

这个右边跟上面右边一样,一个是在上面贡献一个是在下面贡献,而且跟谁贡献无关,都是两个贡献,所以可以消掉。


t y p e = 2 type=2 type=2
( ∏ D ( ⌊ A D ⌋ ) ! φ ( D ) ) ⌊ B D ⌋ ⌊ C D ⌋ \left(\prod\limits_{D}(\left\lfloor \frac{A}{D}\right\rfloor)!^{\varphi(D)}\right)^{\left\lfloor \frac{B}{D}\right\rfloor\left\lfloor \frac{C}{D}\right\rfloor} (D(DA)!φ(D))DBDC
∏ d ∏ d ′ ∏ i = 1 ⌊ A d d ′ ⌋ ∏ j = 1 ⌊ B d d ′ ⌋ gcd ⁡ ( i , j ) d μ ( d ′ ) ⌊ C d d ′ ⌋ \prod\limits_{d}\prod\limits_{d'}\prod\limits_{i=1}^{\left\lfloor \frac{A}{dd'}\right\rfloor}\prod\limits_{j=1}^{\left\lfloor \frac{B}{dd'}\right\rfloor}\gcd(i,j)^{d\mu(d')\left\lfloor \frac{C}{dd'}\right\rfloor} ddi=1ddAj=1ddBgcd(i,j)dμ(d)ddC
∏ D ( ∏ d ∣ D ∏ i = 1 ⌊ A D ⌋ ∏ j = 1 ⌊ B D ⌋ gcd ⁡ ( i , j ) d μ ( D d ) ) ⌊ C D ⌋ \prod\limits_{D}\left(\prod\limits_{d|D}\prod\limits_{i=1}^{\left\lfloor \frac{A}{D}\right\rfloor}\prod\limits_{j=1}^{\left\lfloor \frac{B}{D}\right\rfloor}\gcd(i,j)^{d\mu(\frac{D}{d})}\right)^{\left\lfloor \frac{C}{D}\right\rfloor} DdDi=1DAj=1DBgcd(i,j)dμ(dD)DC
∏ D ( ∏ i = 1 ⌊ A D ⌋ ∏ j = 1 ⌊ B D ⌋ gcd ⁡ ( i , j ) φ ( D ) ) ⌊ C D ⌋ \prod\limits_{D}\left(\prod\limits_{i=1}^{\left\lfloor \frac{A}{D}\right\rfloor}\prod\limits_{j=1}^{\left\lfloor \frac{B}{D}\right\rfloor}\gcd(i,j)^{\varphi(D)}\right)^{\left\lfloor \frac{C}{D}\right\rfloor} Di=1DAj=1DBgcd(i,j)φ(D)DC
∏ D ( ∏ t t ( ∑ i = 1 ⌊ A D ⌋ ∑ j = 1 ⌊ B D ⌋ [ gcd ⁡ ( i , j ) = = t ] ) φ ( D ) ) ⌊ C D ⌋ \prod\limits_{D}\left(\prod\limits_{t}t^{\left(\sum\limits_{i=1}^{\left\lfloor \frac{A}{D}\right\rfloor}\sum\limits_{j=1}^{\left\lfloor \frac{B}{D}\right\rfloor}[\gcd(i,j)==t]\right)\varphi(D)}\right)^{\left\lfloor \frac{C}{D}\right\rfloor} Dtt(i=1DAj=1DB[gcd(i,j)==t])φ(D)DC
∏ D ( ∏ t t ( ∑ i = 1 ⌊ A D t ⌋ ∑ j = 1 ⌊ B D t ⌋ [ gcd ⁡ ( i , j ) = = 1 ] ) φ ( D ) ) ⌊ C D ⌋ \prod\limits_{D}\left(\prod\limits_{t}t^{\left(\sum\limits_{i=1}^{\left\lfloor \frac{A}{Dt}\right\rfloor}\sum\limits_{j=1}^{\left\lfloor \frac{B}{Dt}\right\rfloor}[\gcd(i,j)==1]\right)\varphi(D)}\right)^{\left\lfloor \frac{C}{D}\right\rfloor} Dtt(i=1DtAj=1DtB[gcd(i,j)==1])φ(D)DC
∏ D ( ∏ t t ( ∑ t ′ μ ( t ′ ) ⌊ A D t t ′ ⌋ ⌊ B D t t ′ ⌋ ) φ ( D ) ) ⌊ C D ⌋ \prod\limits_{D}\left(\prod\limits_{t}t^{\left(\sum\limits_{t'}\mu(t')\left\lfloor \frac{A}{Dtt'}\right\rfloor\left\lfloor \frac{B}{Dtt'}\right\rfloor\right)\varphi(D)}\right)^{\left\lfloor \frac{C}{D}\right\rfloor} Dtt(tμ(t)DttADttB)φ(D)DC
∏ D ( ∏ t ∏ t ′ t μ ( t ′ ) ⌊ A D t t ′ ⌋ ⌊ B D t t ′ ⌋ φ ( D ) ) ⌊ C D ⌋ \prod\limits_{D}\left(\prod\limits_{t}\prod\limits_{t'}t^{\mu(t')\left\lfloor \frac{A}{Dtt'}\right\rfloor\left\lfloor \frac{B}{Dtt'}\right\rfloor\varphi(D)}\right)^{\left\lfloor \frac{C}{D}\right\rfloor} D(tttμ(t)DttADttBφ(D))DC
∏ D ( ∏ T ( ∏ t ∣ T t μ ( T t ) ) ⌊ A D T ⌋ ⌊ B D T ⌋ ) ⌊ C D ⌋ φ ( D ) \prod\limits_{D}\left(\prod\limits_{T}\left(\prod\limits_{t|T}t^{\mu(\frac{T}{t})}\right)^{\left\lfloor \frac{A}{DT}\right\rfloor\left\lfloor \frac{B}{DT}\right\rfloor}\right)^{\left\lfloor \frac{C}{D}\right\rfloor\varphi(D)} DT(tTtμ(tT))DTADTBDCφ(D)
预处理最里面的括号里面的值,然后两次整除分块做。

代码

#include<cstdio>
#include<iostream>
#define ll long long

using namespace std;

const int N = 1e5 + 10;
int T, mo, A, B, C;

ll ksm(ll x, ll y, ll p) {
	ll re = 1;
	while (y) {if (y & 1) re = re * x % p; x = x * x % p; y >>= 1;}
	return re;
}

int prime[N], mu[N]; bool np[N];
ll jc[N], inv[N], ii2[N], F2[N], f2[N], fv2[N], phi[N], fakphi[N], fakphiv[N];
void Init() {
	inv[0] = inv[1] = 1; for (int i = 2; i <= 100000; i++) inv[i] = inv[mo % i] * (mo - mo / i) % mo;
	jc[0] = 1; for (int i = 1; i <= 100000; i++) jc[i] = jc[i - 1] * i % mo;
	ii2[0] = 1; for (int i = 1; i <= 100000; i++) ii2[i] = ii2[i - 1] * ksm(i, i, mo) % mo;
	mu[1] = 1; phi[1] = 1;
	for (int i = 2; i <= 100000; i++) {
		if (!np[i]) mu[i] = -1, prime[++prime[0]] = i, phi[i] = i - 1;
		for (int j = 1; j <= prime[0] && i * prime[j] <= 100000; j++) {
			np[i * prime[j]] = 1;
			if (i % prime[j] == 0) {
				phi[i * prime[j]] = phi[i] * prime[j];
				break;
			}
			mu[i * prime[j]] = -mu[i]; phi[i * prime[j]] = phi[i] * (prime[j] - 1);
		}
		mu[i] += mu[i - 1];
		phi[i] += phi[i - 1];
	}
	
	for (int i = 0; i <= 100000; i++) F2[i] = 1;
	for (int i = 1; i <= 100000; i++) {
		f2[i] = i; fv2[i] = ksm(i, mo - 2, mo);
		for (int j = i; j <= 100000; j += i) {
			if (!(mu[j / i] - mu[j / i - 1])) continue;
			F2[j] = F2[j] * (mu[j / i] - mu[j / i - 1] == 1 ? f2[i] : fv2[i]) % mo;
		}
		F2[i] = ksm(F2[i], 1ll * i * i, mo);
		F2[i] = F2[i - 1] * F2[i] % mo;
	}
	
	for (int i = 0; i <= 100000; i++) fakphi[i] = 1; fakphiv[0] = 1;
	for (int i = 1; i <= 100000; i++) {
		for (int j = i; j <= 100000; j += i) {
			ll now = 1; if (mu[j / i] - mu[j / i - 1]) now = (mu[j / i] - mu[j / i - 1] == 1) ? i : inv[i];
			fakphi[j] = fakphi[j] * now % mo;
		}
		fakphi[i] = fakphi[i - 1] * fakphi[i] % mo;
		fakphiv[i] = ksm(fakphi[i], mo - 2, mo);
	}
}

ll sumgcd1(int n, int m, ll p) {
	ll re = 0;
	for (int L = 1, R; L <= n && L <= m; L = R + 1) {
		R = min(n / (n / L), m / (m / L));
		(re += 1ll * (mu[R] - mu[L - 1] + p) % p * (n / L) % p * (m / L) % p) %= p;
	}
	return re;
}

ll prodgcd1(int n, int m) {
	ll re = 1;
	for (int L = 1, R; L <= n && L <= m; L = R + 1) {
		R = min(n / (n / L), m / (m / L));
		ll di = 1; for (int i = L; i <= R; i++) di = di * i % mo;
		re = re * ksm(di, sumgcd1(n / L, m / L, mo - 1), mo) % mo;
	}
	return re;
}

void work1() {
	ll re = ksm(ksm(prodgcd1(A, C), mo - 2, mo), B, mo);
	(re *= ksm(ksm(jc[A], B, mo) * ksm(jc[B], A, mo) % mo, C, mo)) %= mo;
	(re *= ksm(ksm(prodgcd1(A, B), mo - 2, mo), C, mo)) %= mo;
	printf("%lld ", re);
}

ll sumn(ll x, ll p) {
	return 1ll * x * (x + 1) / 2 % p;
}

ll prodgcd2(ll n, ll m) {
	ll re = 1;
	for (int L = 1, R; L <= n && L <= m; L = R + 1) {
		R = min(n / (n / L), m / (m / L));
		re = re * ksm(F2[R] * ksm(F2[L - 1], mo - 2, mo) % mo, sumn(n / L, mo - 1) * sumn(m / L, mo - 1) % (mo - 1), mo) % mo;
	}
	return re;
}

void work2() {
	ll re = ksm(prodgcd2(A, C), (mo - 2) * sumn(B, mo - 1) % (mo - 1), mo);
	(re *= ksm(ii2[A], sumn(B, mo - 1) * sumn(C, mo - 1) % (mo - 1), mo)) %= mo;
	(re *= ksm(ii2[B], sumn(A, mo - 1) * sumn(C, mo - 1) % (mo - 1), mo)) %= mo;
	(re *= ksm(prodgcd2(A, B), (mo - 2) * sumn(C, mo - 1) % (mo - 1), mo)) %= mo;
	printf("%lld ", re);
}

ll prodi3(ll A, ll B, ll C) {
	ll re = 1;
	for (int L = 1, R; L <= A && L <= B && L <= C; L = R + 1) {
		R = min(A / (A / L), min(B / (B / L), C / (C / L)));
		ll now = ksm(jc[A / L], phi[R] - phi[L - 1], mo);
		re = re * ksm(now, (B / L) * (C / L) % (mo - 1), mo) % mo;
	}
	return re;
}

ll prodgcd3s(ll A, ll B) {
	ll re = 1;
	for (int L = 1, R; L <= A && L <= B; L = R + 1) {
		R = min(A / (A / L), B / (B / L));
		ll sum = fakphi[R] * fakphiv[L - 1] % mo;
		(re *= ksm(sum, (A / L) * (B / L) % (mo - 1), mo)) %= mo;
	}
	return re;
}

ll prodgcd3(ll A, ll B, ll C) {
	ll re = 1;
	for (int L = 1, R; L <= A && L <= B && L <= C; L = R + 1) {
		R = min(A / (A / L), min(B / (B / L), C / (C / L)));
		re = re * ksm(prodgcd3s(A / L, B / L), (C / L) * (phi[R] - phi[L - 1]) % (mo - 1), mo) % mo;
	}
	return re;
}

void work3() {
	ll re = ksm(prodgcd3(A, B, C), mo - 2, mo);
	(re *= prodi3(A, B, C)) %= mo;
	(re *= prodi3(B, A, C)) %= mo;
	(re *= ksm(prodgcd3(A, C, B), mo - 2, mo)) %= mo;
	printf("%lld\n", re);
}

int main() {
	scanf("%d %d", &T, &mo);
	Init();
	while (T--) {
		scanf("%d %d %d", &A, &B, &C);
		
		work1();
		work2();
		work3();
	}
	
	return 0;
}
数据中心机房是现代信息技术的核心设施,它承载着企业的重要数据和服务,因此,其基础设计与规划至关重要。在制定这样的方案时,需要考虑的因素繁多,包括但不限于以下几点: 1. **容量规划**:必须根据业务需求预测未来几年的数据处理和存储需求,合理规划机房的规模和设备容量。这涉及到服务器的数量、存储设备的容量以及网络带宽的需求等。 2. **电力供应**:数据中心是能源消耗大户,因此电力供应设计是关键。要考虑不间断电源(UPS)、备用发电机的容量,以及高效节能的电力分配系统,确保电力的稳定供应并降低能耗。 3. **冷却系统**:由于设备密集运行,散热问题不容忽视。合理的空调布局和冷却系统设计可以有效控制机房温度,避免设备过热引发故障。 4. **物理安全**:包括防火、防盗、防震、防潮等措施。需要设计防火分区、安装烟雾探测和自动灭火系统,设置访问控制系统,确保只有授权人员能进入。 5. **网络架构**:规划高速、稳定、冗余的网络架构,考虑使用光纤、以太网等技术,构建层次化网络,保证数据传输的高效性和安全性。 6. **运维管理**:设计易于管理和维护的IT基础设施,例如模块化设计便于扩展,集中监控系统可以实时查看设备状态,及时发现并解决问题。 7. **绿色数据中心**:随着环保意识的提升,绿色数据中心成为趋势。采用节能设备,利用自然冷源,以及优化能源管理策略,实现低能耗和低碳排放。 8. **灾难恢复**:考虑备份和恢复策略,建立异地灾备中心,确保在主数据中心发生故障时,业务能够快速恢复。 9. **法规遵从**:需遵循国家和地区的相关法律法规,如信息安全、数据保护和环境保护等,确保数据中心的合法运营。 10. **扩展性**:设计时应考虑到未来的业务发展和技术进步,保证机房有充足的扩展空间和升级能力。 技术创新在数据中心机房基础设计及规划方案中扮演了重要角色。例如,采用虚拟化技术可以提高硬件资源利用率,软件定义网络(SDN)提供更灵活的网络管理,人工智能和机器学习则有助于优化能源管理和故障预测。 总结来说,一个完整且高效的数据中心机房设计及规划方案,不仅需要满足当前的技术需求和业务目标,还需要具备前瞻性和可持续性,以适应快速变化的IT环境和未来可能的技术革新。同时,也要注重经济效益,平衡投资成本与长期运营成本,实现数据中心的高效、安全和绿色运行。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值