洛谷 P3704 SDOI2017 数字表格
题意:
给定两个整数 \(n, m\),求:
\[\prod_{i = 1} ^ n \prod_{j = 1} ^ m \operatorname{Fib}_{\gcd\left(n, m\right)}
\]
其中 \(\operatorname{Fib}_n\) 表示斐波那契数列的第 \(n\) 项,斐波那契数列按照如下方式递归定义:
\[\begin{equation}
\operatorname{Fib}_n =
\begin{cases}
1 & n = 1\ \text{or}\ n = 2\\
\operatorname{Fib}_{n - 2} + \operatorname{Fib}_{n - 1} & \text{otherwise}\\
\end{cases}
\end{equation}
\]
正文
开始推导!
老套路,先枚举 \(\gcd\left(i, j\right)\), 设 \(d = \gcd\left( i, j \right)\)。
则考虑对于每个可行的 \(d\),对应的 \(\operatorname{Fib}_d\) 被乘了多少次。
显然是:
\[\sum_{i = 1} ^ n \sum_{j = 1} ^ m [\gcd\left(i, j\right) = d]\\
= \sum_{i = 1} ^ {\lfloor\frac{n}{d}\rfloor} \sum_{j = 1} ^ {\lfloor\frac{m}{d}\rfloor} [\gcd\left(i, j\right) = 1]\\
= \sum_{i = 1} ^ {\lfloor\frac{n}{d}\rfloor} \sum_{j = 1} ^ {\lfloor\frac{m}{d}\rfloor} \sum_{t|\gcd\left(i, j\right)} \mu \left(t\right)\\
= \sum_{t = 1} ^ {\lfloor\frac{\min\{n, m\}}{d}\rfloor} \mu \left(t\right) \cdot \lfloor\frac{n}{dt}\rfloor \cdot \lfloor\frac{m}{dt}\rfloor
\]
次。
即:
\[\text{原式} = \prod_{d = 1} ^ {\min\{n, m\}} \operatorname{Fib}_d^{(\sum_{t = 1} ^ {\lfloor\frac{\min\{n, m\}}{d}\rfloor} \mu \left(t\right) \cdot \lfloor\frac{n}{dt}\rfloor \cdot \lfloor\frac{m}{dt}\rfloor)}
\]
换元。设 \(T = dt\),则有:
\[\text{原式} = \prod_{d = 1} ^ {\min\{n, m\}} \operatorname{Fib}_d^{(\sum_{t = 1} ^ {\lfloor\frac{\min\{n, m\}}{d}\rfloor} \mu \left(\frac{T}{d}\right) \cdot \lfloor\frac{n}{T}\rfloor \cdot \lfloor\frac{m}{T}\rfloor)}\\
= \prod_{d = 1} ^ {\min\{n, m\}} (\prod_{t = 1} ^ {\lfloor\frac{\min\{n, m\}}{d}\rfloor} \operatorname{Fib}_d^{\mu \left(\frac{T}{d}\right)}) ^ {\lfloor\frac{n}{T}\rfloor \cdot \lfloor\frac{m}{T}\rfloor}\\
= \prod_{T = 1} ^ {\min\{n, m\}} (\prod_{d | T} \operatorname{Fib}_d ^ {\mu \left(\frac{T}{d}\right)})^{\lfloor\frac{n}{T}\rfloor \cdot \lfloor\frac{m}{T}\rfloor}\]
对于每个 \(T\), 预处理:
\[\prod_{d | T} \operatorname{Fib}_d ^ {\mu \left(\frac{T}{d}\right)}
\]
然后整除分块求解即可。