判断等比,等差数列并求其第k项
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long ll;
const ll M=200907LL;
ll a,b,c,d,k,res;
ll mypow(ll x,ll y){
//求x^y%M的快速幂
ll ret=1LL;
while(y){
if(y&1LL) ret=(ret*x)%M;
y>>=1LL;//二进制整体向右移1
x=x*x%M;
}
return ret;
}
void solve(){
scanf("%lld%lld%lld%lld",&a,&b,&c,&k);
if(c-b==b-a){
//判断是否是等差数列
d=(b-a)%M;
res=(a+(k-1)%M*d)%M;
}
else{
//否则就是等比数列
d=(b/a)%M;
res=a%M*mypow(d,k-1)%M;
}
printf("%lld",res);
}
int main(){
int T;
scanf("%d",&T);
while(T--) solve();
return 0;
}