Description
给定f(n)=n^a+n^(a+1)+...+n^(b-1)+n^b 求f(n)%MOD
Input
输入一个正整数T(T<=10),表示有T组数据,每组数据包括三个整数a,b,n(0<=n,a,b<=1e9)
Output
输出 f(n)%10000000033 的结果
Sample Input
2 1 2 3 2 1 3
Sample Output
12 12
思路:
两数相乘可能会超1e18,所以用到快乘。
代码:
#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 + 1000;
const long long mod = 10000000033;
long long n, a, b;
long long w[1000];
int ca[1000], cb[1000], cc[1000];
void into()
{
w[0] = 1;
for (int i = 1; i <= 1000; i++)
w[i] = w[i - 1] * 10 % mod;
}
LL seek(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 = seek(ans, a, mod);
b = b >> 1;
a = seek(a, a, mod);
}
return ans;
}
int main()
{
int T;
into();
cin >> T;
while (T--)
{
cin >> a >> b >> n;
if (a > b)
swap(a, b);
if (n == 0)
{
cout << 0 << endl;
continue;
}
if (n == 1)
{
cout << b - a + 1 << endl;
continue;
}
LL ans = quick(n - 1, mod - 2, mod);
ans = seek(ans, quick(n, a, mod), mod);
ans = seek(ans, quick(n, b-a+1, mod) - 1, mod);
cout << (ans % mod + mod) % mod << endl;
}
return 0;
}