Xinlv wrote some sequences onthe paper a long time ago, they might be arithmetic or geometric sequences. The numbers are not very clear now, and only thefirst three numbers of each sequence are recognizable. Xinlv wants to know some numbers in these sequences, and he needs your help.
Input
The first line contains an integer N, indicting that there are N sequences. Each ofthe following N lines contain four integers. The first three indicating thefirst three numbers ofthe sequence, andthelast one is K, indicating that we want to know the K-th numbers ofthe sequence.
You can assume 0 < K <= 10^9, andthe other three numbers are inthe range [0, 2^63). All the numbers ofthe sequences are integers. And the sequences are non-decreasing.
Output
Output one line for each test case, thatis, the K-th number module (%) 200907.
Sample Input
212351245
Sample Output
516
#include <iostream>#include <cstdio>#include <algorithm>
using namespace std;
typedef long long ll;
const int mod=200907;
ll quick_mod(ll a,ll b) {
ll ans=1;
while(b) {
if(b&1) ans=(ans*a)%mod;
a=(a*a)%mod;
b>>=1;
}
return ans;
}
int main() {
int t;
scanf("%d",&t);
while(t--) {
ll a,b,c,k;
scanf("%lld%lld%lld%lld",&a,&b,&c,&k);
if(2*b==a+c) {
ll d=(b-a);
ll ans=(a%mod+(k-1)*(b-a)%mod)%mod;
printf("%lld\n",ans);
}
else {
ll q=b/a;
ll ans=(a*quick_mod(q,k-1))%mod;
printf("%lld\n",ans);
}
}
return0;
}
Xinlv wrote some sequences on the paper a long time ago, they might be arithmetic or geometric sequences. The numbers are not very clear now, and only the first three numbers of each sequence are recog