1189: Pell number of columns

Portal: http: //ybt.ssoier.cn: 8088 / problem_show.php pid = 1189?

Description [title]

Pell columns A . 1 , A 2 , A . 3 , . . .

This is defined as, A . 1 = . 1 , A 2 = 2 , . . . , A n- = 2 A n- - . 1 + A n- - 2 ( n- > 2 )

On a given positive integer k, the number of columns required Pell k-th mold 32767 is.

 

[Enter]

Line 1 is the set of n number of test data, followed by n input lines. Each set of test data representing a line, comprising a positive integer k (1≤k <1000000).

[Output]

n lines, each corresponding to an input line of output. The output should be a non-negative integer.

[Sample input]

2
1
8

[Sample Output]

1
408



#include<iostream>
#include<cstring>
using namespace std;
#define N 1000000+10
int n,a[N];
int main()
{
    a[1]=1;
    a[2]=2;
    for(int i=3;i<=N-1;i++)a[i]=(2*a[i-1]+a[i-2])%32767;
    cin>>n;
    for(int i=1;i<=n;i++){
        int as;
        cin>>as;
        cout<<a[as]<<endl;
    }
    // cout<<a[n]<<endl;
}

 

Guess you like

Origin www.cnblogs.com/jzxnl/p/11106484.html