第一种
f ( a , b , c , n ) = ∑ i = 0 n a i + b c f(a,b,c,n)=\sum_{i=0}^n\frac{ai+b}{c} f(a,b,c,n)=i=0∑n?cai+b?
情况一: a ≥ co rb ≥ c a\ge c~or~b \ge c a≥c or b≥c
f ( a , b , c , n ) = f ( a % c , b % c , c , n ) + n ( n + 1 ) 2 ? a c + b c ? ( n + 1 ) f(a,b,c,n)=f(a\%c,b\%c,c,n)+\frac{n(n+1)}{2}\cdot\frac{a}{c}+\frac{b}{c}\cdot(n+1) f(a,b,c,n)=f(a%c,b%c,c,n)+2n(n+1)??ca?+cb??(n+1)
情况二: a <
ba n da <
c a<
b~and~a<
c af ( a , b , c , n ) = ∑ i = 0 n ∑ j = 1 m [ a i + b ≥ c j ] = ( n + 1 ) m ? ∑ j = 0 m ? 1 c j + ( c ? b + a ? 1 ) a = ( n + 1 ) m ? f ( c , c ? b + a ? 1 , a , m ? 1 ) f(a,b,c,n)=\sum_{i=0}^n\sum_{j=1}^m[ai+b\ge cj]=(n+1)m-\sum_{j=0}^{m-1}\frac{cj+(c-b+a-1)}{a}=(n+1)m-f(c,c-b+a-1,a,m-1) f(a,b,c,n)=i=0∑n?j=1∑m?[ai+b≥cj]=(n+1)m?j=0∑m?1?acj+(c?b+a?1)?=(n+1)m?f(c,c?b+a?1,a,m?1)
第二种
【类欧几里得算法推导】 g ( a , b , c , n ) = ∑ i = 0 n i a i + b c g(a,b,c,n)=\sum_{i=0}^ni\frac{ai+b}{c} g(a,b,c,n)=i=0∑n?icai+b?
情况一: a ≥ co rb ≥ c a\ge c~or~b \ge c a≥c or b≥c
g ( a , b , c , n ) = g ( a % c , b % c , c , n ) + n ( n + 1 ) ( 2 n + 1 ) 6 ? a c + n ( n + 1 ) 2 ? b c g(a,b,c,n)=g(a\%c,b\%c,c,n)+\frac{n(n+1)(2n+1)}{6}\cdot\frac{a}{c}+\frac{n(n+1)}{2}\cdot\frac{b}{c} g(a,b,c,n)=g(a%c,b%c,c,n)+6n(n+1)(2n+1)??ca?+2n(n+1)??cb?
情况二: a <
ba n da <
c a<
b~and~a<
c ag ( a , b , c , n ) = ∑ i = 0 n i ∑ j = 1 m [ a i + b ≥ c j ] = g(a,b,c,n)=\sum_{i=0}^ni\sum_{j=1}^m[ai+b\ge cj]= g(a,b,c,n)=i=0∑n?ij=1∑m?[ai+b≥cj]=
1 2 ( m n ( n + 1 ) ? ∑ j = 0 m ? 1 ( c j + ( c ? b + a ? 1 ) a ) 2 + ∑ j = 0 m ? 1 c j + ( c ? b + a ? 1 ) a ) = \frac{1}{2}\left(mn(n+1)-\sum_{j=0}^{m-1}\left(\frac{cj+(c-b+a-1)}{a}\right)^2+\sum_{j=0}^{m-1}\frac{cj+(c-b+a-1)}{a}\right)= 21?(mn(n+1)?j=0∑m?1?(acj+(c?b+a?1)?)2+j=0∑m?1?acj+(c?b+a?1)?)=
1 2 ( m n ( n + 1 ) ? h ( c , c ? b + a ? 1 , a , m ? 1 ) + f ( c , c ? b + a ? 1 , a , m ? 1 ) ) \frac{1}{2}(mn(n+1)-h(c,c-b+a-1,a,m-1)+f(c,c-b+a-1,a,m-1)) 21?(mn(n+1)?h(c,c?b+a?1,a,m?1)+f(c,c?b+a?1,a,m?1))
第三种
h ( a , b , c , n ) = ∑ i = 0 n ( a i + b c ) 2 h(a,b,c,n)=\sum_{i=0}^n\left(\frac{ai+b}{c}\right)^2 h(a,b,c,n)=i=0∑n?(cai+b?)2
情况一: a ≥ co rb ≥ c a\ge c~or~b \ge c a≥c or b≥c
h ( a , b , c , n ) = n ( n + 1 ) ( 2 n + 1 ) 6 ? ( a c ) 2 + ( b c ) 2 ? ( n + 1 ) + a c ? b c n ( n + 1 ) + h(a,b,c,n)=\frac{n(n+1)(2n+1)}{6}\cdot\left(\frac{a}{c}\right)^2+\left(\frac{b}{c}\right)^2\cdot(n+1)+\frac{a}{c}\cdot\frac{b}{c}n(n+1)+ h(a,b,c,n)=6n(n+1)(2n+1)??(ca?)2+(cb?)2?(n+1)+ca??cb?n(n+1)+
2 a c g ( a % c , b % c , c , n ) + 2 b c f ( a % c , b % c , c , n ) + h ( a % c , b % c , c , n ) 2\frac{a}{c}g(a\%c,b\%c,c,n)+2\frac{b}{c}f(a\%c,b\%c,c,n)+h(a\%c,b\%c,c,n) 2ca?g(a%c,b%c,c,n)+2cb?f(a%c,b%c,c,n)+h(a%c,b%c,c,n)
情况二: a <
ba n da <
c a<
b~and~a<
c ah ( a , b , c , n ) = ∑ i = 0 n ∑ j = 1 m [ a i + b ≥ c j ] ( 2 j ? 1 ) = ∑ j = 0 m ? 1 ( 2 j + 1 ) ( n + 1 ? c j + ( c ? b + a ? 1 ) a ) = h(a,b,c,n)=\sum_{i=0}^n\sum_{j=1}^m[ai+b\ge cj](2j-1)=\sum_{j=0}^{m-1}(2j+1)\left(n+1-\frac{cj+(c-b+a-1)}{a}\right)= h(a,b,c,n)=i=0∑n?j=1∑m?[ai+b≥cj](2j?1)=j=0∑m?1?(2j+1)(n+1?acj+(c?b+a?1)?)=
m 2 ( n + 1 ) ? 2 g ( c , c ? b + a ? 1 , a , m ? 1 ) ? f ( c , c ? b + a ? 1 , a , m ? 1 ) m^2(n+1)-2g(c,c-b+a-1,a,m-1)-f(c,c-b+a-1,a,m-1) m2(n+1)?2g(c,c?b+a?1,a,m?1)?f(c,c?b+a?1,a,m?1)
大板子
洛谷P5170
#include
推荐阅读
- HDU 5528【2015长春现场赛 B】 Count a * b
- 类欧几里得算法|[类欧几里得算法 数论] BZOJ 2987 Earthquake
- [数论] Codeforces 819D R #421 D.Mister B and Astronomers & 516E R #292 E. Drazil and His Happy Friends
- 模板 poj2947 Widget Factory 高斯消元
- 【扩展欧几里得】练习题
- 扩展欧几里得【数论
- 数论|hdu 5322 Hope(分治+NTT)
- HDU 5528 Count a × b
- 线性同余方程组
- 数论|AtCoder Beginner Contest 156 C.Rally