1788: Pell series, 1788pell Series
1788: Pell Series
- View
- Submit
- Statistics
- Question
-
Total time limit:
-
3000 ms
-
Memory limit:
-
65536kB
-
Description
-
Pell series a1, a2, a3 ,... the definition is as follows: a1 = 1, a2 = 2 ,..., an = 2 * an −1 + an-2 (n> 2 ).
A positive integer k is given, which indicates the value of 32767 In the k-th modulo of the Pell series.
-
Input
-
The first row is the number of n groups of test data, followed by n rows of input. Each group of test data occupies one row, including a positive integer k (1 ≤ k <1000000 ).
-
Output
-
N rows, each row of output corresponds to an input. The output should be a non-negative integer.
-
Sample Input
-
218
-
Sample output
-
1408
1 #include<iostream> 2 #include<cstdio> 3 #include<queue> 4 #include<cmath> 5 using namespace std; 6 long long int tot=0; 7 long long int a[10000001]; 8 long long int b[10000001]; 9 long long int ans[100000001];10 int main() 11 {12 int n;13 cin>>n;14 for(int i=1;i<=n;i++)15 cin>>a[i];16 b[1]=1;17 b[2]=2;18 for(int i=1;i<=n;i++)19 {20 for(int j=3;j<=a[i];j++)21 {22 b[j]=(2*b[j-1]+b[j-2])%32767;23 24 } 25 }26 for(int i=1;i<=n;i++)27 {28 cout<<b[a[i]];29 cout<<endl;30 }31 return 0;32 }