您的位置:首页 > 产品设计 > UI/UE

题目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//
#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
****************************************************************/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: