/** * */ // #include {{{ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #ifdef LOCAL #include #include #endif using namespace std; // }}} // type {{{ using i8 = int8_t; using u8 = uint8_t; using i16 = int16_t; using u16 = uint16_t; using i32 = int32_t; using u32 = uint32_t; using i64 = int64_t; using u64 = uint64_t; using i128 = __int128_t; using u128 = __uint128_t; template using MaxHeap = priority_queue, less>; template using MinHeap = priority_queue, greater>; // }}} // hide {{{ #ifdef __clang__ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wunused-const-variable" #endif // }}} // 適宜調整 constexpr bool AUTOFLUSH = false; constexpr int IOS_PREC = 12; constexpr int INF_I32 = 1'010'000'000; constexpr i64 INF_I64 = 1'010'000'000'000'000'000LL; constexpr auto INF = INF_I64; constexpr double EPS = 1e-12; constexpr i64 MOD = 1'000'000'007; // hide {{{ #ifdef __clang__ #pragma clang diagnostic pop #endif // }}} // util {{{ constexpr i32 I32_MAX = numeric_limits::max(); constexpr i32 I32_MIN = numeric_limits::min(); constexpr i64 I64_MAX = numeric_limits::max(); constexpr i64 I64_MIN = numeric_limits::min(); constexpr double PI = 3.14159265358979323846; template class RecursiveFunc { public: RecursiveFunc(F&& f) : f_(f) {} template decltype(auto) operator()(Args&&... args) const { return f_(*this, forward(args)...); } private: F f_; }; template auto RECURSIVE(F&& f) { return RecursiveFunc>(forward(f)); } template int GETBIT(T x, int i) { return (x>>i) & 1; } template T SETBIT(T x, int i) { return x | (T(1)< T CLEARBIT(T x, int i) { return x & ~(T(1)< constexpr const T& MAX(const T& x, const T& y) { return std::max(x, y); } template constexpr const T& MAX(const T& x, const T& y, Comp comp) { return std::max(x, y, comp); } template constexpr T MAX(initializer_list ilist) { return std::max(ilist); } template constexpr T MAX(initializer_list ilist, Comp comp) { return std::max(ilist, comp); } template constexpr const T& MIN(const T& x, const T& y) { return std::min(x, y); } template constexpr const T& MIN(const T& x, const T& y, Comp comp) { return std::min(x, y, comp); } template constexpr T MIN(initializer_list ilist) { return std::min(ilist); } template constexpr T MIN(initializer_list ilist, Comp comp) { return std::min(ilist, comp); } template constexpr T ABS(T x) { static_assert(is_signed::value, "ABS(): argument must be signed"); return x < 0 ? -x : x; } template constexpr T abs_diff(T x, T y) { return x < y ? y-x : x-y; } template constexpr bool is_odd(T x) { return x % 2 != 0; } template constexpr bool is_even(T x) { return x % 2 == 0; } template constexpr bool parity_same(T x, T y) { return (is_odd(x) && is_odd(y)) || (is_even(x) && is_even(y)); } template constexpr int cmp(T x, T y) { return (y < x) - (x < y); } template constexpr int sgn(T x) { return cmp(x, T(0)); } constexpr i64 ipow(i64 a, i64 b) { assert(b >= 0); i64 res(1); for(i64 i = 0; i < b; ++i) res *= a; return res; } pair divmod(i64 a, i64 b) { return make_pair(a/b, a%b); } constexpr i64 div_ceil(i64 a, i64 b) { return a/b + (((a<0)^(b>0)) && (a%b)); } constexpr i64 div_floor(i64 a, i64 b) { return a/b - (((a>0)^(b>0)) && (a%b)); } constexpr i64 modulo(i64 a, i64 b) { assert(0 < b); i64 r = a % b; return r >= 0 ? r : r+b; } template constexpr T CLAMP(T x, T lo, T hi) { assert(lo <= hi); if(x < lo) return lo; else if(hi < x) return hi; else return x; } template bool chmax(T& xmax, const U& x) { if(xmax < x) { xmax = x; return true; } else { return false; } } template bool chmin(T& xmin, const U& x) { if(x < xmin) { xmin = x; return true; } else { return false; } } template constexpr int SIZE(const T& c) { return static_cast(c.size()); } template constexpr int SIZE(const T (&)[N]) { return static_cast(N); } template int argfind(InputIt first, InputIt last, const T& x) { auto it = find(first, last, x); return distance(first, it); } template int argmax(InputIt first, InputIt last) { auto it = max_element(first, last); return distance(first, it); } template int argmin(InputIt first, InputIt last) { auto it = min_element(first, last); return distance(first, it); } template bool alltrue(InputIt first, InputIt last) { return all_of(first, last, [](bool b) { return b; }); } template bool anytrue(InputIt first, InputIt last) { return any_of(first, last, [](bool b) { return b; }); } template bool allfalse(InputIt first, InputIt last) { return !anytrue(first, last); } template bool anyfalse(InputIt first, InputIt last) { return !alltrue(first, last); } // hash {{{ template struct myhash { size_t operator()(const T& x) const { hash h; return h(x); } }; template size_t myhash_value(const T& x) { return hash()(x); } template void myhash_combine(size_t& seed, const T& x) { seed ^= myhash_value(x) + 0x9e3779b9 + (seed<<6) + (seed>>2); } template struct myhash> { size_t operator()(const pair& p) const { size_t seed = 0; myhash_combine(seed, p.first); myhash_combine(seed, p.second); return seed; } }; template = nullptr> void TUPLEHASH(size_t&, const tuple&) {} template = nullptr> void TUPLEHASH(size_t& seed, const tuple& t) { myhash_combine(seed, get(t)); TUPLEHASH(seed, t); } template struct myhash> { size_t operator()(const tuple& t) const { size_t seed = 0; TUPLEHASH(seed, t); return seed; } }; template void SEQHASH(size_t& seed, const Seq& v) { for(const auto& e : v) myhash_combine(seed, e); } template struct myhash> { size_t operator()(const vector& v) const { size_t seed = 0; SEQHASH(seed, v); return seed; } }; template struct myhash> { size_t operator()(const array& v) const { size_t seed = 0; SEQHASH(seed, v); return seed; } }; template using HashSet = unordered_set>; template using HashMap = unordered_map>; template using HashMultiSet = unordered_multiset>; template using HashMultiMap = unordered_multimap>; // }}} template void vec_emplace_front(vector& v, Args&&... args) { v.emplace(begin(v), args...); } template pair::iterator, bool> insert_or_assign(map& m, const K& k, const V& v) { auto it = m.lower_bound(k); if(it != end(m) && !m.key_comp()(k,it->first)) { it->second = v; return make_pair(it, false); } else { auto it_ins = m.insert(it, make_pair(k,v)); return make_pair(it_ins, true); } } template pair::iterator, bool> insert_or_assign(HashMap& m, const K& k, const V& v) { auto it = m.find(k); if(it != end(m)) { it->second = v; return make_pair(it, false); } else { auto it_ins = m.insert(it, make_pair(k,v)); return make_pair(it_ins, true); } } template string TO_STRING(const T& x) { ostringstream out; out << x; return out.str(); } template string JOIN(InputIt first, InputIt last, const string& sep) { ostringstream out; while(first != last) { out << *first++; if(first != last) out << sep; } return out.str(); } template auto SUM(InputIt first, InputIt last) { using T = typename iterator_traits::value_type; return accumulate(first, last, T()); } template void UNIQ(T& c) { c.erase(unique(begin(c), end(c)), end(c)); } template enable_if_t::value==0> ARRAY_FOREACH(T& e, F f) { f(e); } template enable_if_t::value!=0> ARRAY_FOREACH(Array& ary, F f) { for(auto& e : ary) ARRAY_FOREACH(e, f); } template enable_if_t::value!=0> ARRAY_FILL(Array& ary, const U& v) { ARRAY_FOREACH(ary, [&v](auto& elem) { elem = v; }); } template T POP_BACK(vector& que) { T x = que.back(); que.pop_back(); return x; } template T POP_BACK(deque& que) { T x = que.back(); que.pop_back(); return x; } template T POP_FRONT(deque& que) { T x = que.front(); que.pop_front(); return x; } template T POP(stack& stk) { T x = stk.top(); stk.pop(); return x; } template T POP(queue& que) { T x = que.front(); que.pop(); return x; } template T POP(priority_queue& que) { T x = que.top(); que.pop(); return x; } template void RD(T& x) { cin >> x; #ifdef LOCAL if(!cin) assert(false); #endif } template void RD(vector& v, int n) { v.reserve(n); for(int i = 0; i < n; ++i) { T e; RD(e); v.emplace_back(e); } } template void RD(array& v) { for(size_t i = 0; i < N; ++i) { RD(v[i]); } } // 出力 {{{ // FPRINTSEQ {{{ template ostream& FPRINTSEQ(ostream& out, InputIt first, InputIt last) { while(first != last) { out << *first++; if(first != last) out << ' '; } return out; } template ostream& PRINTSEQ(InputIt first, InputIt last) { return FPRINTSEQ(cout, first, last); } template ostream& DPRINTSEQ(InputIt first, InputIt last) { #ifdef LOCAL FPRINTSEQ(cerr, first, last); #endif return cerr; } // }}} // 1次元生配列 {{{ template ostream& FPRINTARRAY1(ostream& out, const T (&c)[N]) { return FPRINTSEQ(out, begin(c), end(c)); } template ostream& PRINTARRAY1(const T (&c)[N]) { return FPRINTARRAY1(cout, c); } template ostream& DPRINTARRAY1(const T (&c)[N]) { #ifdef LOCAL FPRINTARRAY1(cerr, c); #endif return cerr; } // }}} // 2次元生配列 {{{ template ostream& FPRINTARRAY2(ostream& out, const T (&c)[N1][N2]) { out << '\n'; for(const auto& e : c) { FPRINTARRAY1(out, e) << '\n'; } return out; } template ostream& PRINTARRAY2(const T (&c)[N1][N2]) { return FPRINTARRAY2(cout, c); } template ostream& DPRINTARRAY2(const T (&c)[N1][N2]) { #ifdef LOCAL FPRINTARRAY2(cerr, c); #endif return cerr; } // }}} // 非mapコンテナ {{{ template ostream& operator<<(ostream& out, const vector& c) { return FPRINTSEQ(out, begin(c), end(c)); } // 特別扱い template ostream& operator<<(ostream& out, const vector>& c) { out << '\n'; for(const auto& e : c) { out << e << '\n'; } return out; } // 特別扱い ostream& operator<<(ostream& out, const vector& c) { out << '\n'; for(const string& e : c) { out << e << '\n'; } return out; } template ostream& operator<<(ostream& out, const deque& c) { return FPRINTSEQ(out, begin(c), end(c)); } template ostream& operator<<(ostream& out, const set& c) { return FPRINTSEQ(out, begin(c), end(c)); } template ostream& operator<<(ostream& out, const HashSet& c) { return out << set(begin(c), end(c)); } template ostream& operator<<(ostream& out, const multiset& c) { return FPRINTSEQ(out, begin(c), end(c)); } template ostream& operator<<(ostream& out, const HashMultiSet& c) { return out << multiset(begin(c), end(c)); } template ostream& operator<<(ostream& out, const array& c) { return FPRINTSEQ(out, begin(c), end(c)); } // }}} // mapコンテナ {{{ template ostream& FPRINTMAP(ostream& out, InputIt first, InputIt last) { out << "{\n"; for(auto it = first; it != last; ++it) { out << " " << it->first << " : " << it->second << '\n'; } out << "}\n"; return out; } template ostream& PRINTMAP(InputIt first, InputIt last) { return FPRINTMAP(cout, first, last); } template ostream& DPRINTMAP(InputIt first, InputIt last) { #ifdef LOCAL FPRINTMAP(cerr, first, last); #endif return cerr; } template ostream& operator<<(ostream& out, const map& c) { return FPRINTMAP(out, begin(c), end(c)); } template ostream& operator<<(ostream& out, const HashMap& c) { return out << map(begin(c), end(c)); } template ostream& operator<<(ostream& out, const multimap& c) { return FPRINTMAP(out, begin(c), end(c)); } template ostream& operator<<(ostream& out, const HashMultiMap& c) { return out << multimap(begin(c), end(c)); } // }}} // stack/queue/priority_queue {{{ template ostream& operator<<(ostream& out, stack c) { while(!c.empty()) { out << c.top(); c.pop(); if(!c.empty()) out << ' '; } return out; } template ostream& operator<<(ostream& out, queue c) { while(!c.empty()) { out << c.front(); c.pop(); if(!c.empty()) out << ' '; } return out; } template ostream& operator<<(ostream& out, priority_queue c) { while(!c.empty()) { out << c.top(); c.pop(); if(!c.empty()) out << ' '; } return out; } // }}} // pair/tuple {{{ template ostream& operator<<(ostream& out, const pair& p) { return out << '(' << p.first << ',' << p.second << ')'; } template = nullptr> ostream& FPRINTTUPLE(ostream& out, const tuple&) { if(sizeof...(TS) == 0) out << '('; return out << ')'; } template = nullptr> ostream& FPRINTTUPLE(ostream& out, const tuple& t) { if(I == 0) out << '('; else out << ','; out << get(t); return FPRINTTUPLE(out, t); } template ostream& operator<<(ostream& out, const tuple& t) { return FPRINTTUPLE(out, t); } // }}} // PRINT {{{ ostream& FPRINT(ostream& out) { return out; } template ostream& FPRINT(ostream& out, const T& x, const TS& ...args) { out << x; if(sizeof...(args)) out << ' '; return FPRINT(out, args...); } template ostream& FPRINTLN(ostream& out, const TS& ...args) { FPRINT(out, args...); return out << '\n'; } template ostream& PRINT(const TS& ...args) { return FPRINT(cout, args...); } template ostream& PRINTLN(const TS& ...args) { return FPRINTLN(cout, args...); } template ostream& DPRINT(const TS& ...args) { #ifdef LOCAL FPRINT(cerr, args...); #endif return cerr; } template ostream& DPRINTLN(const TS& ...args) { #ifdef LOCAL FPRINTLN(cerr, args...); #endif return cerr; } // }}} // }}} void FLUSH() { cout.flush(); } [[noreturn]] void EXIT() { #ifdef LOCAL cout.flush(); cerr.flush(); #else FLUSH(); #endif //quick_exit(0); // does not work on codeforces _Exit(0); } struct IoInit { IoInit() { #ifndef LOCAL cin.tie(nullptr); ios::sync_with_stdio(false); #endif cout << fixed << setprecision(IOS_PREC); #ifdef LOCAL cerr << fixed << setprecision(IOS_PREC); #endif if(AUTOFLUSH) cout << unitbuf; } } IOINIT; #define FOR(i, start, end) for(i64 i = (start); i < (end); ++i) #define REP(i, n) FOR(i, 0, n) #define ALL(f,c,...) (([&](decltype((c)) cc) { return (f)(begin(cc), end(cc), ## __VA_ARGS__); })(c)) #define GENERIC(f) ([](auto&&... args) -> decltype(auto) { return (f)(forward(args)...); }) #define DBG(x) DPRINTLN('L', __LINE__, ':', #x, ':', (x)) #define PAIR make_pair #define TUPLE make_tuple // }}} /** * a^b (mod m) * * 事前条件: * a >= 0 && b >= 0 */ i64 pow_modulo(i64 a, i64 b, i64 m) { i64 res = 1; for(; b > 0; b >>= 1) { if(b & 1) { res *= a; res %= m; } a *= a; a %= m; } return res; } /** * mod p での a の逆元 */ i64 inv_modulo(i64 a, i64 p) { return pow_modulo(a, p-2, p); } /** * mod p 上での演算をクラス化してみるテスト * p は素数とする */ template class ModPT { public: ModPT() : v_(0) {} ModPT(i64 v) : v_(v%P) {} ModPT& operator+=(const ModPT& rhs) { v_ += rhs.v_; v_ %= P; return *this; } ModPT& operator-=(const ModPT& rhs) { v_ = (v_+P) - rhs.v_; v_ %= P; return *this; } ModPT& operator*=(const ModPT& rhs) { v_ *= rhs.v_; v_ %= P; return *this; } ModPT inv() const { return ModPT(inv_modulo(v_, P)); } ModPT pow(i64 x) const { return ModPT(pow_modulo(v_, x, P)); } friend ostream& operator<<(ostream& out, const ModPT

& a) { return out << a.v_; } private: i64 v_; }; template const ModPT

operator+(const ModPT

& lhs, const ModPT

& rhs) { return ModPT

(lhs) += rhs; } template const ModPT

operator+(const ModPT

& lhs, i64 rhs) { return ModPT

(lhs) += rhs; } template const ModPT

operator+(i64 lhs, const ModPT

& rhs) { return ModPT

(rhs) += lhs; } template const ModPT

operator-(const ModPT

& lhs, const ModPT

& rhs) { return ModPT

(lhs) -= rhs; } template const ModPT

operator-(const ModPT

& lhs, i64 rhs) { return ModPT

(lhs) -= rhs; } template const ModPT

operator-(i64 lhs, const ModPT

& rhs) { return ModPT

(rhs) -= lhs; } template const ModPT

operator*(const ModPT

& lhs, const ModPT

& rhs) { return ModPT

(lhs) *= rhs; } template const ModPT

operator*(const ModPT

& lhs, i64 rhs) { return ModPT

(lhs) *= rhs; } template const ModPT

operator*(i64 lhs, const ModPT

& rhs) { return ModPT

(rhs) *= lhs; } using ModP = ModPT<17>; #if 0 // スタックオーバーフローで落ちる ModP f(i64 n) { static ModP memo[1000001]; static bool done[1000001] {}; assert(n >= 1); if(n <= 3) return 0; if(n == 4) return 1; if(!done[n]) { memo[n] = f(n-1) + f(n-2) + f(n-3) + f(n-4); done[n] = true; } return memo[n]; } #endif ModP table[1000001]; void make_table() { table[1] = 0; table[2] = 0; table[3] = 0; table[4] = 1; FOR(i, 5, SIZE(table)) { table[i] = table[i-1] + table[i-2] + table[i-3] + table[i-4]; } } void solve() { make_table(); i64 Q; RD(Q); REP(_, Q) { i64 n; RD(n); PRINTLN(table[n]); } } signed main(signed /*argc*/, char** /*argv*/) { solve(); EXIT(); }