【题解】「2018 集训队互测 Day 3」蒜头的奖杯
题目大意:给定\(n,A,B,C,D,E,F\),求
\[\sum_{i=1}^n\sum_{j=1}^n\sum_{k=1}^nA_iB_jC_kD_{\gcd(i,j)}E_{\gcd(i,k)}F_{\gcd(j,k)}
\]
首先容易想到三个同时算的方法:对\(D,E,F\)进行反演,得
\[\sum_{i=1}^nA_i\sum_{p|i}D_p\sum_{p|j}^nB_j\sum_{r|j}F_r\sum_{r|k}^nC_k\sum_{q|k}E_q[i\%q=0]
\]
设数组\(tmp\)初始值为\(A\),可以先变换再与一个函数对应位置相乘,进行\(5\)次。要分别对\(1\text{~}n\)的每一个起始位置算一次,\(O(n^2\log n)\),喜提TLE
。
三个同时算不好算,考虑拆开算,原式即
\[\sum_{i=1}^n\sum_{j=1}^nA_iB_jD_{\gcd(i,j)}\sum_{k=1}^nC_kE_{\gcd(i,k)}F_{\gcd(j,k)}
\]
同时对\(E\)和\(F\)进行莫比乌斯反演得
\[\sum_{i=1}^n\sum_{j=1}^nA_iB_jD_{\gcd(i,j)}\sum_{k=1}^nC_k\sum_{q|i,q|k}E_q\sum_{r|j,r|k}F_r
\]
于是,根据套路,将被拆开的\(C,E,F\)提到前面,再提出下标的\(\gcd\)
\[\begin{align}
&\;\;\;\;\sum_{i=1}^n\sum_{j=1}^nA_iB_jD_{\gcd(i,j)}\sum_{k=1}^nC_k\sum_{q|i,q|k}E_q\sum_{r|j,r|k}F_r\\
&=\sum_{k=1}^nC_k\sum_{q|k}E_q\sum_{r|k}F_r\sum_{i=1}^{\lfloor\frac nq\rfloor}\sum_{j=1}^{\lfloor\frac nr\rfloor}A_{iq}B_{jr}D_{\gcd(iq,jr)}\\
&=\sum_{s=1}^n\sum_{q=1}^{\lfloor\frac ns\rfloor}\sum_{r=1}^{\lfloor\frac n{sq}\rfloor}[\gcd(q,r)=1]E_{sq}F_{sr}\sum_{k=1}^{\lfloor\frac n{sqr}\rfloor}C_{sqrk}\sum_{i=1}^{\lfloor\frac n{sq}\rfloor}\sum_{j=1}^{\lfloor\frac n{sr}\rfloor}A_{isq}B_{jsr}D_{s\cdot\gcd(iq,jr)}
\end{align}\]
设\(C'_i=\sum_{j=1}^{\lfloor\frac ni\rfloor}C_{ij},A'_i=A_{si},B'_i=B_{si},D'_i=D_{si},m=\lfloor\frac ns\rfloor\),则:
\[\begin{align}
&\;\;\;\;\sum_{s=1}^n\sum_{q=1}^{\lfloor\frac ns\rfloor}\sum_{r=1}^{\lfloor\frac n{sq}\rfloor}[\gcd(q,r)=1]E_{sq}F_{sr}\sum_{k=1}^{\lfloor\frac n{sqr}\rfloor}C_{sqrk}\sum_{i=1}^{\lfloor\frac n{sq}\rfloor}\sum_{j=1}^{\lfloor\frac n{sr}\rfloor}A_{isq}B_{jsr}D_{s\cdot\gcd(iq,jr)}\\
&=\sum_{s=1}^n\sum_{q=1}^{\lfloor\frac ns\rfloor}\sum_{r=1}^{\lfloor\frac n{sq}\rfloor}[\gcd(q,r)=1]E_{sq}F_{sr}C'_{sqr}\sum_{i=1}^{\lfloor\frac mq\rfloor}\sum_{j=1}^{\lfloor\frac mr\rfloor}A'_{iq}B'_{jr}D'_{\gcd(iq,jr)}
\end{align}\]
将\(D'\)反演,得
\[\begin{align}
&\;\;\;\;\sum_{s=1}^n\sum_{q=1}^{\lfloor\frac ns\rfloor}\sum_{r=1}^{\lfloor\frac n{sq}\rfloor}[\gcd(q,r)=1]E_{sq}F_{sr}C'_{sqr}\sum_{i=1}^{\lfloor\frac mq\rfloor}\sum_{j=1}^{\lfloor\frac mr\rfloor}A'_{iq}B'_{jr}\sum_{p|iq,p|jr}D'_p\\
&=\sum_{s=1}^n\sum_{q=1}^{\lfloor\frac ns\rfloor}\sum_{r=1}^{\lfloor\frac n{sq}\rfloor}[\gcd(q,r)=1]E_{sq}F_{sr}C'_{sqr}\sum_{q|i}^mA'_i\sum_{p|i}D'_p\sum_{p|j}B'_j[j\%r=0]
\end{align}\]
借鉴之前的思路,枚举\(s,q\),设\(tmp_i=A'_i[i\%q=0]\),对\(tmp\)进行变换\(tmp'_i=D'_i\sum_{d|i}tmp_i\)得\(tmp'\),再对\(tmp'\)进行变换\(tmp''_d=B'_d\sum_{d|i}tmp'_i\)得\(tmp''\)。
再枚举\(r\),则\(s,q,r\)对答案的贡献为\(E_{sq}F_{sr}C'_{sqr}\sum_{i=1}^{\lfloor\frac mr\rfloor}tmp''_{ir}\)
注意常数优化
Please not contact lydsy2012@163.com!