Description
给定f(n)=(a+1)*n^a+(a+2)*n^(a+1)+...+b*n^(b-1) 求f(n)%10000000033
Input
输入一个正整数T(T<=10),表示有T组数据,每组数据包括三个整数a,b,n (0<=n<=10^9,1<=a <= b-1<=10^20)
Output
输出 f(n)%10000000033 的结果
Sample Input
1 1 2 3
Sample Output
6
思路:
化简一下式子,得到:
得到 S(a),S(b),用快速幂模板
注意:这题数非常大,两数相乘用快乘模板。
代码:
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<utility>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<math.h>
#include<map>
using namespace std;
typedef long long LL;
typedef unsigned long long ull;
#define per(i,a,b) for(int i=a;i<=b;i++)
#define ber(i,a,b) for(int i=a;i>=b;i--)
const int N = 1e5 + 5;
const LL mod = 10000000033;
long long n, a, b,aa,bb;
char sa[33], sb[33];
LL mul(LL a, LL b, LL mod)
{
LL ans = 0;
while (b)
{
if (b & 1)
ans =(ans+a)%mod;
b >>= 1;
a = (a + a) % mod;
}
return ans;
}
LL quick(LL a, LL b, LL mod)
{
LL ans = 1;
while (b)
{
if (b & 1)
ans = mul(ans, a,mod);
b >>= 1;
a = mul(a, a,mod);
}
return ans;
}
void into()
{
int lena = (int)strlen(sa+1), lenb = (int)strlen(sb + 1);
per(i, 1, lena)
{
a = (a*10 + sa[i] - '0') % mod;
aa = (aa*10 + sa[i] - '0') % (mod - 1);
}
per(i, 1, lenb)
{
b = (b*10 + sb[i] - '0') % mod;
bb = (bb*10 +sb[i] -'0') % (mod - 1);
}
}
int main()
{
int T;
cin >> T;
while (T--)
{
a = aa = b = bb = 0;
cin >> sa+1 >> sb+1 >> n;
into();
if (n == 0)
{
cout << 0 << endl;
continue;
}
if (n == 1)
{
LL ni = quick(2, mod - 2, mod);
cout << ((mul(mul(b, b + 1, mod),ni,mod)- mul(mul(a, a + 1, mod), ni, mod)) % mod + mod) % mod << endl;
continue;
}
LL ni = quick(n - 1, mod - 2, mod);
LL anb = quick(n, bb, mod),ana=quick(n,aa,mod);
anb = mul(b, anb, mod) - mul(ni,anb-1,mod);
anb = (anb+mod) % mod;
anb = mul(anb, ni, mod);
ana = mul(a, ana, mod) - mul(ni, ana - 1, mod);
ana = (ana % mod + mod) % mod;
ana = mul(ana, ni, mod);
cout <<((anb - ana)%mod+mod)%mod << endl;
}
return 0;
}