题目1442:A sequence of numbers 数列题
2014-05-15 20:41
417 查看
Problem Description
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.
Input
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
Output one line for each test case, that is, the K-th number module (%) 200907.
Sample Input
2 1 2 3 5 1 2 4 5
Sample Output
5 16
Source
2009 Multi-University Training Contest 1 - Host by TJU
Recommend
gaojie
给出数列的前三项,数列要么是等差数列、要么是等比数列,求第K项。
很简单,注意细节处理。
注意数据类型的溢出,要用long long,中间过程防止溢出
//注意%200907//
Problem Description
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.
Input
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
Output one line for each test case, that is, the K-th number module (%) 200907.
Sample Input
2 1 2 3 5 1 2 4 5
Sample Output
5 16
Source
2009 Multi-University Training Contest 1 - Host by TJU
Recommend
gaojie
给出数列的前三项,数列要么是等差数列、要么是等比数列,求第K项。
很简单,注意细节处理。
注意数据类型的溢出,要用long long,中间过程防止溢出
//注意%200907//
#include<iostream> using namespace std; long long Z(long long q, long long n) { long long ans = 1; long long a = q; while(n != 0) { if(n%2 == 1) { ans *= a; ans %= 200907; } n /= 2; a *= a; a %= 200907; } return ans; } int main() { long long a,b,c; long long k; long long n; long long sum; cin>>n; while(n--) { cin>>a>>b>>c>>k; if((b-a) == (c-b)) { sum = (a + ((b-a)*(k-1))%200907)%200907; cout<<sum<<endl; } else { sum = (a*(Z(b/a, k-1))%200907)%200907; cout<<sum<<endl; } } } /************************************************************** Problem: 1442 User: hrdjmax2 Language: C++ Result: Accepted Time:10 ms Memory:1520 kb ****************************************************************/
相关文章推荐
- 题目1442:A sequence of numbers(数列计算以及二分求幂运用)
- 【九度OJ】题目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
- 九度OJ题目1442:A sequence of numbers
- 58-题目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
- HDU 2817 A sequence of numbers(数列,简单题)
- HDOJ 题目2187 A sequence of numbers(快速幂水)
- 九度OJ1442:A sequence of numbers 解题报告
- 题目58:A sequence of numbers
- 题目58:A sequence of numbers
- 九度OJ 1442 A sequence of numbers
- 九度OJ 1442 A sequence of numbers
- 九度OJ-1442:A sequence of numbers