-
题目描述:
-
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
-
-
-
// arithmetic or geometric sequences.cpp : 定义控制台应用程序的入口点。 // #include "stdafx.h" struct e { long a; long b; long c; long th; }buf[5]; int _tmain(int argc, _TCHAR* argv[]) { int n; while (scanf("%d",&n)) { for (int i = 0; i < n; i++) { scanf("%ld%ld%ld%ld",&buf[i].a,&buf[i].b,&buf[i].c,&buf[i].th); } for (int i = 0; i < n; i++) { if (buf[i].b-buf[i].a==buf[i].c-buf[i].b)//是等差 { long ans=buf[i].a+(buf[i].th-1)*(buf[i].b-buf[i].a); printf("%ld\n",ans%200907); } else { long a=buf[i].b/buf[i].a; long ans=1; long b=buf[i].th-1; while (b) //!!!二分求幂!!! { if(b%2) ans*=a; b/=2; a*=a; } printf("%ld",ans*a%200907); } } } return 0; }
-