Run ID:28053
提交时间:2022-06-12 19:15:11
#include <iostream> #include <assert.h> #include <ctime> using namespace std; const int mod_num = 32767; const int max_k = 1000000; // PellSeq is non-recursive int PellSeq(int n) { int PellSn_2 = 1; // Pell Sequence a1 = 1 int PellSn_1 = 2; // Pell Sequence a2 = 2 int PellSn; // Pell Sequence an = ? if (n <= 2) { return n; } for(int i=3; i<=n; i++) { PellSn = (2*PellSn_1 + PellSn_2) % mod_num; PellSn_2 = PellSn_1; PellSn_1 = PellSn; } return PellSn; } int main() { int n; cin >> n; int k; for (int i=1; i<=n; i++) { cin >> k; cout << PellSeq(k) << endl; } return 0; }