1875: A sequence of numbers
题目描述
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 3 5 8
2 4 8 7
输出样例
15
128
提示
来源or类型
AC 代码:
#include<iostream>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
long long T;
long long a,b,c,d,i;
cin>>T;
while(T--)
{
cin>>a>>b>>c>>d;
if(a==b && b==c )
{
cout<<a%200907<<endl;
continue;
}
if(b-a==c-b)
{
long long s=b-a;
cout<<a%200907+((((d-1)%200907)*(s%200907))%200907)%200907<<endl;
}
else
{
long long l=(b/a)%200907;
long long temp=1;
d--;
a=a%200907;
while(d) //关键的地方,才开始因为没有想到这里,直接用的是for语句,不是WA,就是超时,然后换这个思路才AC,现在还是不明白为什么for不行,很尴尬的;
{
if(d%2==1)
{
temp=temp*l;
temp%=200907;
}
l=(l*l)%200907;
d/=2;
}
long long sum=(a*temp)%200907;
cout<<sum<<endl;
}
}
return 0;
}