A sequence of numbers (quick power)
Description
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 recognizable. xinlv wants to know some numbers in these sequences, and he needs your help.
Input requirements
The first line contains an integer N, indicting that there are N sequences. each of the following N lines contain four integers. the first three indicating the first three numbers of the sequence, and the last one isK, Indicating that we want to know the K-th numbers of the sequence.
You can assume 0 <K <= 10 ^ 9, and the other three numbers are in the range [0, 2 ^ 63 ). all the numbers of the sequences are integers. and the sequences are non-decreasing.
Output requirements
Output one line for each test case, that is, the K-th numberModule (%) 200907.
Assume that
21 2 3 51 2 4 5
Output
516
The question is very simple, that is, to give you a sequence of the first three items, the sequence is not an equality or an equality ratio, let you calculate the K more than 200907.
The code for quick idempotence is
int fastpow(int a,int b){int r=1,base=a;while(b!=0){if(b&1)r*=base;base*=base;b>>=1;}return r;}
Ac code
#include
#include#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;int MOD=200907;long long fastpow(long long q,long long n){long long r=1;while(n){if(n&1)r=r%MOD*(q%MOD)%MOD;q=q%MOD*(q%MOD)%MOD;n>>=1;}return r;}void solve();int main(){solve();return 0;}void solve(){ long long t,a1,a2,a3,n,d,ans,q;cin>>t;while(t--){cin>>a1>>a2>>a3>>n;if(a2*2==a1+a3){d=a2-a1;ans=(a1+(n-1)*d%MOD)%MOD;}else{q=a2/a1;ans=a1*fastpow(q,n-1)%MOD;}cout<