HDU 2817 A sequence of numbers
题目链接:A sequence of numbers
代码如下:
#include<iostream>
using namespace std;
typedef long long int ll;
#define N 200907
#define check(x,y,z)(2*y==(x+z))
ll a = 0, b = 0, c = 0, k = 0;
ll fastpow()
{
ll base = b / a, ans = 1;
k--;
while (k) {
if (k & 1) {
ans = ans * base % N;
}
base = base * base % N;
k >>= 1;
}
return ans * (a % N) % N;
}
int main()
{
int n = 0;
cin >> n;
while (n--) {
cin >> a >> b >> c >> k;
if (check(a, b, c)) {
cout << (a % N + (b - a) % N * ((k - 1) % N)) % N << endl;
}
else {
cout << fastpow() << endl;
}
}
return 0;
}