[NOI2016] 循环之美
题意
想法
对题目进行一些变化,说白是求这个柿子
\(f(n,m,k) = \sum\limits_{i = 1}^n\sum\limits_{j = 1} ^ m [(i,j) == 1][(j,k) == 1]\\
=\sum\limits_{i = 1}^n\sum\limits_{j = 1} ^ m [(i,j) == 1]\sum\limits_{d|(j,k)}\mu(d)\\
=\sum\limits_{d|k}\mu(d)\sum\limits_{i = 1}^n\sum\limits_{j = 1} ^ {\lfloor \frac{m}{i} \rfloor} [(i,jd) == 1]\\
=\sum\limits_{d|k}\mu(d)\sum\limits_{i = 1}^n\sum\limits_{j = 1} ^ {\lfloor \frac{m}{i} \rfloor} [(i,j) == 1][(j,d) == 1]\\
=\sum\limits_{d|k}\mu(d)f(m/d,n,d)\)
然后我们进行递归求解就行,\(f(0,m,k) = f(n,0,k) = 0\),\(k = 1,\sum\limits_{i = 1}^n\sum\limits_{j = 1} ^ {m} [(i,j) == 1] = \sum\limits_{d}^n\mu(d)\frac{m}{d}\frac{n}{d}\)