题目1442:A sequence of numbers 九度OJ

来源:互联网 发布:ztree check源码 编辑:程序博客网 时间:2024/05/16 05:42

题目1442:A sequence of numbers

时间限制:1 秒

内存限制:128 兆

特殊判题:

提交:4160

解决:1059

题目描述:

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.

样例输入:
21 2 3 51 2 4 5
样例输出:
516
//题目1442:题中所给的序列为算术几何序列,也就是等差或者等比序列//所以,在读入序列之后,利用序列前三个数判断该序列是等比序列还是等差序列。//据说直接判断是否为等差序列比较省时间。如果该序列不是等差序列 ,则必定是等比序列 // 等差序列利用公式即可求得------an=a1+(n-1)*d//等比序列,遵照二分求幂的原则可求得---------an=a1*q^(n-1) //You can assume 0 < K <= 10^9, and the other three numbers are in the range [0, 2^63)//关于题中变量 大小的 设定 ,另外三个数都是2^63 -1,说明需要用 long long 来存储// 输出 取模   Output one line for each test case, that is, the K-th number module (%) 200907. #include <cstdio>#define ret 200907int main(){int n;while(scanf("%d",&n)!=EOF){while(n--){long long a,b,c,k;long long ans;scanf("%lld%lld%lld%lld",&a,&b,&c,&k); //判断是等差还是等比if((b-a)==(c-b)){//是等差数列  ans=a%ret+(((k-1)%ret)*((b-a)%ret))%ret;//对此处数值的范围 不是很明了 ,在哪里取模才正确 }else{    //是等比数列 --------二分求幂  long long q=b/a;long long m=k-1;ans=1;while(m!=0){if(m%2==1){ans=(ans*q)%ret;}m=m/2;q=(q*q)%ret;}ans=((a%ret)*ans)%ret;}printf("%lld\n",ans); }}return 0;} 




0 0
原创粉丝点击