一本通 1615:【例 1】序列的第 k 个数
序列的第k个数
快速幂
Code:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
//Mystery_Sky
//
#define Mod 200907
#define M 10001000
#define ll long long
int n, k, a[M];
ll quickPow(ll x, ll k)
{
ll ret = 1;
while(k) {
if(k & 1) ret = (ret * x) % Mod;
k >>= 1;
x = (x * x) % Mod;
}
return ret % Mod;
}
int t;
int main() {
scanf("%d", &t);
while(t--) {
ll a, b, c, k;
scanf("%lld%lld%lld%lld", &a, &b, &c, &k);
if((a + c) == (2 * b)) {
ll d = (b - a) % Mod;
printf("%lld\n", (a + ((k - 1) * d) % Mod) % Mod);
}
else {
ll q = (b / a) % Mod;
printf("%lld\n", (a % Mod * quickPow(q, k-1)) % Mod);
}
}
return 0;
}
唯愿,青春不辜负梦想,未来星辰闪耀