传送门:loj138
题解
被标题坑进去,断断续续做了一天。。。确实是“类欧几里得算法”啊(雾。。。
设答案为函数 f ( a , b , c , n , k 1 , k 2 ) = ∑ i = 0 n i k 1 ⌊ a i + b c ⌋ k 2 f(a,b,c,n,k_1,k_2)=\sum\limits_{i=0}^ni^{k_1}\lfloor\dfrac{ai+b}{c}\rfloor^{k_2} f(a,b,c,n,k1,k2)=i=0∑nik1⌊cai+b⌋k2
考虑以下情况:
-
⌊ a i + b c ⌋ \lfloor\dfrac{ai+b}{c}\rfloor ⌊cai+b⌋为常量( a = 0 a=0 a=0或 ⌊ a n + b c ⌋ = 0 \lfloor\dfrac{an+b}{c}\rfloor=0 ⌊can+b⌋=0),直接拉格朗日插值算出 ∑ i = 0 n i k 1 \sum\limits_{i=0}^ni^{k_1} i=0∑nik1即可。
-
a ≥ c a\geq c a≥c或 b ≥ c b\geq c b≥c, f ( a , b , c , n , k 1 , k 2 ) = ∑ i = 0 n i k 1 ( ⌊ a c ⌋ ⋅ i + ⌊ b c ⌋ + ⌊ i ⋅ ( a % c ) + b % c c ⌋ ) k 2 f(a,b,c,n,k_1,k_2)=\sum\limits_{i=0}^ni^{k_1}(\lfloor\dfrac{a}{c}\rfloor·i+\lfloor\dfrac{b}{c}\rfloor+\lfloor\dfrac{i·(a\%c)+b\%c}{c}\rfloor)^{k_2} f(a,b,c,n,k1,k2)=i=0∑nik1(⌊ca⌋⋅i+⌊cb⌋+⌊ci⋅(a%c)+b%c⌋)k2,二项式展开一下得到若干 λ ∑ i = 0 n i k 1 ( ⌊ i ⋅ ( a % c ) + b % c c ⌋ ) k 2 \lambda\sum\limits_{i=0}^n i^{k_1} (\lfloor\dfrac{i·(a\%c)+b\%c}{c}\rfloor)^{k_2} λi=0∑nik1(⌊ci⋅(a%c)+b%c⌋)k