// yukicoder: No.657 テトラナッチ数列 Easy // 2019.4.22 bal4u // 周期性に注目。周期 4912 #include #include #if 1 #define gc() getchar_unlocked() #define pc(c) putchar_unlocked(c) #else #define gc() getchar() #define pc(c) putchar(c) #endif int in() { int n = 0; int c = gc(); do n = 10*n + (c & 0xf), c = gc(); while (c >= '0'); return n; } char ans[17][3] = {"0","1","2","3","4","5","6","7","8","9","10", "11","12","13","14","15","16"}; void outs(int n) { pc(ans[n][0]); if (n >= 10) pc(ans[n][1]); pc('\n'); } #define MOD 17 #define PERIOD 4912 int a[5000] = {0,0,0,1,1,2,4,8,15,29}; int main() { int i, s, Q; s = 2; for (i = 5; i < 5000; i++) { a[i] = s, s = (s + MOD + a[i] - a[i-4]) % MOD; } Q = in(); while (Q--) outs(a[(in()-1) % PERIOD]); return 0; }