$$
\begin {aligned}
ANS & = \prod _ {i = 1} ^ n \prod _ {j = 1} ^ m f _ {(i, j)} \\
& = \prod _ {d = 1} ^ n f _ d ^ {\sum _ {i = 1} ^ n \sum _ {j = 1} ^ m [(i, j) = d]} \\
\end {aligned}
$$
对于指数部分:
$$
\begin {aligned}
\sum _ {i = 1} ^ n \sum _ {j = 1} ^ m [(i, j) = d] & = \sum _ {i = 1} ^ {\lfloor \frac n d \rfloor} \sum _ {j = 1} ^ {\lfloor \frac m d \rfloor}[(i, j) = 1] \\
& = \sum _ {i = 1} ^ {\lfloor \frac n d \rfloor} \sum _ {j = 1} ^ {\lfloor \frac m d \rfloor}\sum _ {e | (i, j)} \mu(e) \\
& = \sum _ {e = 1} ^ n \mu(e) \sum _ {i = 1} ^ {\lfloor \frac n {de} \rfloor} \sum _ {j = 1} ^ {\lfloor \frac m {de} \rfloor}\\
\end {aligned}
$$
令 $T = de$ ,那么有:
$$
\begin {aligned}
ANS & = \prod _ {d = 1} ^ n f _ d ^ {\sum _ {e = 1} ^ n \mu(e) \sum _ {i = 1} ^ {\lfloor \frac n {de} \rfloor} \sum _ {j = 1} ^ {\lfloor \frac m {de} \rfloor}} \\
& = \prod _ {T = 1} ^ n \prod _ {d | T} f _ d ^ {\mu(\frac T d) \sum _ {i = 1} ^ {\lfloor \frac n T \rfloor} \sum _ {i = 1} ^ {\lfloor \frac m T \rfloor}} \\
& = \prod _ {T = 1} ^ n (\prod _ {d | T} f _ d ^ {\mu(\frac T d)})^ {\lfloor \frac n T \rfloor\lfloor \frac m T \rfloor}
\end {aligned}
$$
预处理 $\prod _ {d | T} f _ d ^ {\mu(\frac T d)}$ 的前缀和,数论分块。
查看代码
1 |
|