ybt 1189:Pell数列
ybt 1202:Pell数列
OpenJudge NOI 2.2 1788:Pell数列
OpenJudge NOI 2.3 1788:Pell数列
#include <bits/stdc++.h>
using namespace std;
int a[1000005];
int main()
{
int n, x;
a[1] = 1, a[2] = 2;
for(int i = 3; i <= 1000000; ++i)
a[i] = (2*a[i-1] + a[i-2])%32767;
cin >> n;
for(int i = 1; i <= n; ++i)
{
cin >> x;
cout << a[x] << endl;
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int main()
{
int ct, p;
cin >> ct;
for(int i = 1; i <= ct; ++i)
{
cin >> p;
if(p <= 2)
cout << p << endl;//第1项是1,第2项是2
else
{
int a = 1, b = 2, t;
for(int j = 3; j <= p; ++j)
{
t = b;
b = (2*b + a)%32767;
a = t;
}
cout << b << endl;
}
}
return 0;
}