单位根反演
定理
\([n\mid a] = \dfrac1n\sum_{k=0}^{n-1}\omega_n^{ak}\)
证明
使用等比数列求和
a ≠ 0 (mod n)
公比不为 1
原式 = \(\dfrac1n \times\dfrac{\omega_n^{an}-1}{\omega_n^a-1} = \dfrac1n \times\dfrac{1-1}{\omega_n^a-1} = 0\)
a = 0 (mod n)
公比为 1
原式 = \(\dfrac1n\times n\times \omega_n^0 = 1\)
应用
\([a\equiv b\mod n] = [a-b\equiv 0\mod n] = [n\mid(a-b)] = \dfrac1n\sum_{k=0}^n\omega_n^{(a-b)k}\)
\[\begin{align}
&\sum_{i=0}^n\binom ni\cdot s^i\cdot a_{i\% 4}\\
&= \sum_{i=0}^n\binom ni\cdot s^i\sum_{j=0}^3a_j[i=j\mod4]\\
&= \sum_{i=0}^n\binom ni\cdot s^i\sum_{j=0}^3a_j\frac14\sum_{k=0}^3\omega_4^{k(i-j)}\\
&= \frac14\sum_{j=0}^3a_j\sum_{i=0}^n\binom nis^i\sum_{k=0}^3\omega_4^{ki}\omega_4^{-kj}\\
&= \frac14\sum_{j=0}^3a_j\sum_{k=0}^3\omega_4^{-kj}\sum_{i=0}^n\binom nis^i\omega_4^{ki}\\
&= \frac14\sum_{j=0}^3a_j\sum_{k=0}^3\omega_4^{-kj}(1+s\omega_4^k)^n
\end{align}
\]
\(\left\lfloor\dfrac ik\right\rfloor = \dfrac {i - i\mod k}k\)
原式等于:
\[\frac1k\sum_{i=0}^n\binom ni p^i (i-i\mod k)\\
\frac1k\left[\sum_{i=0}^n\binom ni p^ii-\sum_{i=0}^n\binom ni p^i(i\mod k)\right]
\]
分开考虑:
\[ \sum_{i=0}^n\binom nip^ii\\
np\sum_{i=0}^n\binom {n-1}{i-1}p^{i-1}\\
np\sum_{i=0}^{n-1}\binom {n-1}ip^i\\
np(p+1)^{n-1}
\]
\[ \sum_{i=0}^n\binom nip^i(i\mod k)\\
\sum_{i=0}^n\binom nip^i\sum_{j=0}^{k-1}j[i\mod k =j]\\
\frac1k\sum_{i=0}^n\binom nip^i\sum_{j=0}^{k-1}j\sum_{t=0}^{k-1}\omega_k^{t(i-j)}\\
\frac1k\sum_{j=0}^{k-1}j\sum_{t=0}^{k-1}\omega_k^{-tj}\sum_{i=0}^n\binom nip^i\omega_k^{ti}\\
\frac1k\sum_{j=0}^{k-1}j\sum_{t=0}^{k-1}\omega_k^{-tj}(1+p\omega_k^t)^n\\
\frac1k\sum_{t=0}^{k-1}(1+p\omega_k^t)^n\sum_{j=0}^{k-1}j(\omega_k^{-t})^j
\]
总复杂度是 O(k log n)
附:
\[\begin{align}
S(n,k) &= \sum_{i=0}^{n-1}ik^i\\
kS(n,k)-S(n,k) &= \sum_{i=0}^{n-1}ik^{i+1} - \sum_{i=0}^{n-1}ik^i\\
&= \sum_{i=1}^n(i-1)k^i - \sum_{i=1}^{n-1}ik^i\\
&= -\sum_{i=1}^{n-1}k^i + (n-1)k^n\\
&= \frac{1-k^n}{k-1} + 1 + (n-1)k^n
\end{align}
\]
于是 \(S(n,k) = \dfrac{\dfrac{1-k^n}{k-1} + 1 + (n-1)k^n}{k-1}\)
由于 k 总是 n 次单位根, 于是 \(S(n,k) = \dfrac n{k-1}\)
若 k = 1, \(S(n,1) = \sum_{i=0}^{n-1} i = \dfrac{n(n-1)}2\)