时间限制:1 秒
内存限制:128 兆
特殊判题:否
提交:1396
解决:309
-
题目描述:
-
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.
-
输入:
-
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.
-
输出:
-
Output one line for each test case, that is, the K-th number module (%) 200907.
-
样例输入:
-
2 1 2 3 5 1 2 4 5
-
样例输出:
-
5 16
//1442
#include<cstdio>
const int MOD = 200907;
int
main(void)
{
int N;
while(~scanf("%d",&N))
{
while(N--)
{
long long arr[4];
int k;
long long ans = 0;
scanf("%lld%lld%lld%d",&arr[1],&arr[2],&arr[3],&k);
if((arr[3]-arr[2])==(arr[2]-arr[1]))//等差
{
long long m = arr[3]-arr[2];
ans = arr[1];
ans = (ans + ((k-1)%MOD)*(m%MOD))%MOD;//公式
}
else if(arr[3]%arr[2]==0 && arr[2]%arr[1] ==0
&& arr[3]/arr[2]==arr[2]/arr[1])//等比
{
long long m = arr[3]/arr[2];
ans = arr[1];
k--;
while(k>0)
{
if(k & 1)//快速幂
{
ans = (ans*m)%MOD;//对过程取模
}
m = (m*m)%MOD;
k /= 2;
}
}
printf("%d\n",ans%MOD);
}
}
return 0;
}