题目1442:A sequence of numbers 九度OJ
2017-04-24 23:15
423 查看
题目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.
样例输入:
样例输出:
时间限制: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.
样例输入:
2 1 2 3 5 1 2 4 5
样例输出:
5 16
//题目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 200907 int 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; }
相关文章推荐
- 【九度OJ】题目1442:A sequence of numbers 解题报告
- 九度OJ1442:A sequence of numbers 解题报告
- 【九度】题目1442:A sequence of numbers
- 九度 题目1442:A sequence of numbers
- 九度题目1442:A sequence of numbers
- 题目1442:A sequence of numbers
- 题目1442:A sequence of numbers
- 九度OJ题目1442:A sequence of numbers
- 题目1442:A sequence of numbers
- 题目1442:A sequence of numbers 数列题
- 题目1442:A sequence of numbers(数列计算以及二分求幂运用)
- 题目1442:A sequence of numbers
- 58-题目1442:A sequence of numbers
- 【九度OJ】题目1262:Sequence Construction puzzles(I)_构造全递增序列
- 九度OJ-1442:A sequence of numbers
- HDOJ 题目2187 A sequence of numbers(快速幂水)
- 题目58:A sequence of numbers
- 题目58:A sequence of numbers
- 九度OJ 题目1043:Day of Week
- 九度 oj 题目1446:Head of a Gang