#include "bits/stdc++.h" using namespace std; typedef long long ll; typedef pair pii; typedef pair pll; const int INF = 1e9; const ll LINF = 1e18; template ostream& operator << (ostream& out,const pair& o){ out << "(" << o.first << "," << o.second << ")"; return out; } template ostream& operator << (ostream& out,const vector& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; } template ostream& operator << (ostream& out,const vector >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; } template ostream& operator << (ostream& out,const map& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; } templatevector make_v(size_t a){return vector(a);} templateauto make_v(size_t a,Ts... ts){return vector(ts...))>(a,make_v(ts...));} template typename enable_if::value==0>::type fill_v(T &t,const V &v){t=v;} template typename enable_if::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);} /* 問題文============================================================ ================================================================= 解説============================================================= ================================================================ */ // https://satanic0258.github.io/snippets/math/NTT.html // Description: 整数列a[i],b[i]から列c[k]=sum{a[i]*b[k-i]}を生成する.任意modに対応.O(NlogN). namespace NTT { std::vector tmp; size_t sz = 1; inline int powMod(int n, int p, int m) { int res = 1; while (p) { if (p & 1) res = (ll)res * n % m; n = (ll)n * n % m; p >>= 1; } return (int)res; } inline int invMod(int n, int m) { return powMod(n, m - 2, m); } template struct NTTPart { static std::vector ntt(std::vector a, bool inv = false) { size_t mask = sz - 1; size_t p = 0; for (size_t i = sz >> 1; i >= 1; i >>= 1) { auto& cur = (p & 1) ? tmp : a; auto& nex = (p & 1) ? a : tmp; int e = powMod(PrimitiveRoot, (Mod - 1) / sz * i, Mod); if (inv) e = invMod(e, Mod); int w = 1; for (size_t j = 0; j < sz; j += i) { for (size_t k = 0; k < i; ++k) { nex[j + k] = (cur[((j << 1) & mask) + k] + (ll)w * cur[(((j << 1) + i) & mask) + k]) % Mod; } w = (ll)w * e % Mod; } ++p; } if (p & 1) std::swap(a, tmp); if (inv) { int invSz = invMod(sz, Mod); for (size_t i = 0; i < sz; ++i) a[i] = (ll)a[i] * invSz % Mod; } return a; } static std::vector mul(std::vector a, std::vector b) { a = ntt(a); b = ntt(b); for (size_t i = 0; i < sz; ++i) a[i] = (ll)a[i] * b[i] % Mod; a = ntt(a, true); return a; } }; constexpr int M[] = {1224736769, 469762049, 167772161}; constexpr int PR[] = {3, 3, 3}; constexpr int NTT_CONVOLUTION_TIME = 3; /* X := max(a)*max(b)*min(|a|, |b|) のとき, NTT_CONVOLUTION_TIME <- 1: X < 1224736769 = 1.2*10^ 9 ~ 2^30 NTT_CONVOLUTION_TIME <- 2: X < 575334854091079681 = 5.8*10^17 ~ 2^59 NTT_CONVOLUTION_TIME <- 3: X < 2^86 (32bit * 32bit * 10^7くらいまで) */ inline void garner(std::vector *c, int mod) { if (NTT_CONVOLUTION_TIME == 1) { for(auto& x : c[0]) x %= mod; } else if (NTT_CONVOLUTION_TIME == 2) { const int r01 = invMod(M[0], M[1]); for (size_t i = 0; i < sz; ++i) { c[1][i] = (c[1][i] - c[0][i]) * (ll)r01 % M[1]; if (c[1][i] < 0) c[1][i] += M[1]; c[0][i] = (c[0][i] + (ll)c[1][i] * M[0]) % mod; } } else if (NTT_CONVOLUTION_TIME == 3) { const int R01 = invMod(M[0], M[1]); const int R02 = invMod(M[0], M[2]); const int R12 = invMod(M[1], M[2]); const int M01 = (ll)M[0] * M[1] % mod; for (size_t i = 0; i < sz; ++i) { c[1][i] = (c[1][i] - c[0][i]) * (ll)R01 % M[1]; if (c[1][i] < 0) c[1][i] += M[1]; c[2][i] = ((c[2][i] - c[0][i]) * (ll)R02 % M[2] - c[1][i]) * R12 % M[2]; if (c[2][i] < 0) c[2][i] += M[2]; c[0][i] = (c[0][i] + (ll)c[1][i] * M[0] + (ll)c[2][i] * M01) % mod; } } } std::vector mul(std::vector a, std::vector b, int mod) { for (auto& x : a) x %= mod; for (auto& x : b) x %= mod; size_t m = a.size() + b.size() - 1; sz = 1; while (m > sz) sz <<= 1; tmp.resize(sz); a.resize(sz, 0); b.resize(sz, 0); std::vector c[NTT_CONVOLUTION_TIME]; if (NTT_CONVOLUTION_TIME >= 1) c[0] = NTTPart::mul(a, b); if (NTT_CONVOLUTION_TIME >= 2) c[1] = NTTPart::mul(a, b); if (NTT_CONVOLUTION_TIME >= 3) c[2] = NTTPart::mul(a, b); for (auto& v : c) v.resize(m); garner(c, mod); return c[0]; } }; // !!! CHECK NTT_CONVOLUTION_TIME !!! constexpr ll MOD = 1000000007; constexpr int MAXN = 2000001; template Type solve(Type res = Type()){ ll p; cin >> p; ll Q; cin >> Q; vector a(MAXN); a[1] = 0; a[2] = 1; for(int i = 3; i < MAXN;i++){ a[i] = p*a[i-1]%MOD + a[i-2]; a[i] %= MOD; } auto b = a; vector c(NTT::mul(a,b,MOD)); while(Q--){ ll q; cin >> q; cout << c[q] << endl; } return res; } int main(void) { cin.tie(0); ios::sync_with_stdio(false); solve(0); // cout << fixed << setprecision(12) << solve() << endl; return 0; }