niangniang~

开始就先上一道水题吧。非常水。非常水。水的快被淹死了。

大体的意思是。所给的一串数字,要么是等比数列( geometric),要么是算术数列(arithmetic),a1+a2=a3的那种。

输入:第一行是数列数n,接下来就是n行数列,头3个是a1 a2 a3,最后一个是位置m

输出:按照应有规律输出am。

上题:

A sequence of numbers

Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other)
 

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

 

#include<iostream>
#include<math.h>

using namespace std;

long int num[3];
long int k;
long int re;

void sequence(long int *num,long int k);

int main()
{
    int nq;
    cin>>nq;
    for(int i=0;i<nq;i++)
    {
        cin>>num[0];
        cin>>num[1];
        cin>>num[2];
        cin>>k;
        sequence(num,k);
    }
    return 0;
}

void sequence(long int *num,long int k)
{
    if((num[1]-num[0])==(num[2]-num[1]))
    {
        long int d=0;
        d=(num[1]-num[0]);
        re=num[0]+d*(k-1);
        cout<<re<<endl;
    }else{

          if(num[1]!=0&&num[0]!=0&&((num[1]/num[0])==(num[2]/num[1])))
          {
            long int d=0;
            d=(num[1]/num[0]);
            re=num[0]*pow(d,(k-1));
            cout<<re<<endl;
          }
    }
}

水得我都不想写注释了。不过这么简单的题还是让我啰里吧嗦写了这么多。

完毕~~~