Problem 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
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 is K, 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.
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
Output one line for each test case, that is, the K-th number module (%) 200907.
Sample Input
2 1 2 3 5 1 2 4 5
Sample Output
5 16等比数列,等差数列。要用二分求幂,也要用到64位扩展// (A*B)%M = ((A%M)*(B%M))%M // (b^14)%M = (b^8)%M * (b^4)%M * (b^2)%M // (b^8)%M = (b^4)%M * (b^4)%M // (b^4)%M = (b^2)%M * (b^2)%M // .... #include <stdio.h> #define M 200907 __int64 power(__int64 base,__int64 exp) { if(exp==0) return 1; if(exp==1) return base; __int64 result=power(base,exp/2)%M; result*=result; if(exp%2==1) result=base%M*result%M; return result; } /*__int64 power(__int64 q,__int64 n) { __int64 sum=1; while(n) { if(n&1) { sum*=q;sum%=M; } q=(q*q)%M; n/=2; } return sum; } */ int main() { int n; __int64 a[4]; __int64 s; int k; int i; __int64 d; __int64 q; scanf("%d",&n); while(n--) { for(i=0;i<3;i++) scanf("%I64d",&a[i]); scanf("%d",&k); if(a[1]-a[0]==a[2]-a[1]) //等差 { d=a[1]-a[0]; a[0]%=M;d%=M;k%=M; s=(a[0]+(k-1)*d)%M; } else { q=a[1]/a[0]; s=( (a[0]%M)*power(q,k-1) )%M; } printf("%I64d\n",s); } return 0; }