hdu_2817_高速幂

时间:2021-07-09 19:51:20

水~

#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <set>
#include <queue>
#include <map>
using namespace std;
#define MAX(x,y) (((x)>(y))?(x):(y))
#define MIN(x,y) (((x)<(y))?(x):(y))
#define N 500010
#define pi acos(-1.0)
#define mod 200907
#define inf 100000000
typedef long long ll;
typedef unsigned long long ull;
ll powmod(ll a,ll n){
ll ans=1;
ll tmp=a;
while(n){
if(n&1){
ans*=tmp;
ans%=mod;
}
n>>=1;
tmp*=tmp;
tmp%=mod;
}
return ans;
} int main(){
int t;
scanf("%d",&t);
ll a,b,c,n,ans;
while(t--){
scanf("%lld%lld%lld%lld",&a,&b,&c,&n);
if(b*2==a+c){
ans=(a+(n-1)*(b-a)%mod)%mod;
}
else {
ans=a*powmod(b/a,n-1)%mod;
}
printf("%I64d\n",ans);
}
return 0;
}