2014
02-17

# 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.

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.

2
1 2 3 5
1 2 4 5

5
16

HDU2817 A sequence of numbers

AC代码：

//对于这种数据正好几乎要超过int的范围却远小于long long的范围的题目，直接全部用long long
#include<cstdio>
using namespace std;
const long long mod = 200907;

long long pow_mod(long long x,long long a,long long n)//a^b mod mod
{
if(a==0) return 1;
long long ans = pow_mod(x,a/2,n);
long long temp = (ans*ans)%n;
if(a%2) temp = (temp*x)%n;
return temp;
}

/*
long long pow_mod(long long a,long long b,long long n)  //a^b mod n
{
long long ret=1;
for (; b; b>>=1,a=(long long)(((long long)a)*a%n))
if (b&1)
ret=(long long)(((long long)ret)*a%n);
//printf("%d\n",ret);
return ret;
}
*/
int main()
{
int t;
scanf("%d",&t);

while(t--)
{
long long  a1,a2,a3;
long long k;
scanf("%I64d%I64d%I64d%I64d",&a1,&a2,&a3,&k);
//if(a1==a2)
// printf("%.0lf\n",a1%mod);

if(a2-a1==a3-a2)//等差数列
{
/*
long long d = (long long)(a2-a1);
long long a = (long long)a1;
int temp = (a%mod+((d%mod)*((k-1)%mod)))%mod;
printf("%d\n",temp);
*/
long long d = (a2-a1)%mod;
long long temp = ((a1%mod)+((d%mod)*((k-1)%mod)))%mod;
printf("%I64d\n",temp);

}
else//等比数列
{
/*
long long p1 = (a2/a1);
long long p = (long long)p1;
long long a = (long long)a1;
int temp = ((a%mod)*(pow_mod(p,k-1,mod)))%mod;
printf("%d\n",temp);
*/
long long p=a2/a1;//p的值可能超过int的范围，如果此处用int则必定WA
long long  temp = ((a1%mod)*(pow_mod(p,k-1,mod)))%mod;
printf("%I64d\n",temp);

}

}
return 0;
}

1. 以色列人自己都承认输了，而且不是52辆梅卡瓦坦克被真主党民兵打坏，真主党民兵宣布击毁180多辆梅卡瓦坦克，我取中间数，120辆梅卡瓦坦克被打坏，就这样还没有打进黎巴嫩腹地