等比数列求和
- 很久没更新了 怎会绘世呢?
拿来主义 -> 指路
简而言之 等差为a,前k项的和
ll sum(ll a,ll k, ll mod)
{
ll ans = 0;
ll sum = a; //S(y)
ll mul = 1; //a^x
while (k) {
if (k&1) {
ans = (ans + mul * sum) % mod;
mul = mul * a % mod;
}
sum = sum * (a + 1) % mod;
a = a * a % mod;
k >>= 1;
}
return ans;
}