\[\begin{aligned}
F(a, b, c, n)&=\sum_{i=0}^n \lfloor \frac{ai+b}c\rfloor\&=\frac{n(n+1)}2\lfloor\frac ab\rfloor + (n+1)\lfloor\frac bc\rfloor+\sum_{i=0}^n\lfloor\frac{a‘i+b‘}c\rfloor\&=\frac{n(n+1)}2\lfloor\frac ab\rfloor + (n+1)\lfloor\frac bc\rfloor+\sum_{i=0}^n\sum_{j=1}^m[cj\leq a‘i+b‘]\&=\frac{n(n+1)}2\lfloor\frac ab\rfloor + (n+1)\lfloor\frac bc\rfloor+\sum_{j=1}^m[a‘i>cj-b‘-1]\&=\frac{n(n+1)}2\lfloor\frac ab\rfloor + (n+1)\lfloor\frac bc\rfloor+\sum_{j=0}^{m-1}n-\lfloor\frac{cj+c-b‘-1}a‘\rfloor\&=\frac{n(n+1)}2\lfloor\frac ab\rfloor + (n+1)\lfloor\frac bc\rfloor+nm-F(c, c-b‘-1,a, m-1)
\end{aligned}
\]
\[\begin{aligned}
G(a,b,c,n)&=\sum_{i=0}^n[\frac{ai+b}c]^2\&=\sum_{i=0}([\frac ac]i+\frac bc+[\frac{a‘i+b‘}c])^2\&=\sum_{i=0}[\frac ac]^2i^2+2[\frac ac][\frac bc]i+2[\frac ac]i[\frac{a‘i+b‘}c]+[\frac bc]^2+2[\frac bc][\frac{a‘i+b‘}c]+[\frac{a‘i+b‘}c]^2\\end{aligned}
\]
\[\begin{aligned}
G(a,b,c,n)&=\sum_{i=0}^n[\frac{ai+b}c]^2\&=\sum_{i=0}^n2(\sum_{j=1}^m[cj\leq ai+b]j)-[\frac{ai+b}c]\&=\sum_{i=0}^n2(\sum_{j=0}^{m-1}[ai>cj+c-b-1](j+1))-[\frac{ai+b}c]\&=-F(a, b, c, n)+\sum_{j=0}^{m-1}2(n-[\frac {cj+c-b-1}a])(j+1)\&=-F(a, b, c, n)+m(m+1)n-2H(c, c-b-1, a, m-1)-2F(c, c-b-1, a, m-1)
\end{aligned}
\]
\[\begin{aligned}
H(a,b,c,n)&=\sum_{i=0}^ni[\frac{ai+b}c]\&=\sum_{i=0}
\end{aligned}
\]
类欧几里得算法
原文:https://www.cnblogs.com/ynycoding/p/14928364.html