/* #region Head */ #pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #include using namespace std; using ll = long long; using ull = unsigned long long; using ld = long double; using pll = pair; template using vc = vector; template using vvc = vc>; using vll = vc; using vvll = vvc; using vld = vc; using vvld = vvc; using vs = vc; using vvs = vvc; #define REP(i, m, n) for (ll i = (m), i##_len = (ll)(n); i < i##_len; ++(i)) #define REPM(i, m, n) for (ll i = (m), i##_max = (ll)(n); i <= i##_max; ++(i)) #define REPR(i, m, n) for (ll i = (m), i##_min = (ll)(n); i >= i##_min; --(i)) #define REPD(i, m, n, d) for (ll i = (m), i##_len = (ll)(n); i < i##_len; i += (d)) #define REPMD(i, m, n, d) for (ll i = (m), i##_max = (ll)(n); i <= i##_max; i += (d)) #define REPI(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++) #define ALL(x) begin(x), end(x) #define SIZE(x) ((ll)(x).size()) #define PREM(c) \ sort(all(c)); \ for (bool c##p = 1; c##p; c##p = next_permutation(all(c))) #define UNIQ(v) v.erase(unique(ALL(v)), v.end()); constexpr ll INF = 1'010'000'000'000'000'017LL; constexpr ll MOD = 1'000'000'007LL; // 1e9 + 7 constexpr ld EPS = 1e-12; constexpr ld PI = 3.14159265358979323846; // vector入力 template istream &operator>>(istream &is, vc &vec) { for (T &x : vec) is >> x; return is; } // vector出力 (for dump) template ostream &operator<<(ostream &os, vc &vec) { ll len = SIZE(vec); os << "{"; for (int i = 0; i < len; i++) os << vec[i] << (i == len - 1 ? "" : ", "); os << "}"; return os; } // vector出力 (inline) template ostream &operator>>(ostream &os, vc &vec) { ll len = SIZE(vec); for (int i = 0; i < len; i++) os << vec[i] << (i == len - 1 ? "\n" : " "); return os; } // pair入力 template istream &operator>>(istream &is, pair &pair_var) { is >> pair_var.first >> pair_var.second; return is; } // pair出力 template ostream &operator<<(ostream &os, pair &pair_var) { os << "(" << pair_var.first << ", " << pair_var.second << ")"; return os; } // map出力 template ostream &operator<<(ostream &os, map &map_var) { os << "{"; REPI(itr, map_var) { os << *itr; itr++; if (itr != map_var.end()) os << ", "; itr--; } os << "}"; return os; } // set 出力 template ostream &operator<<(ostream &os, set &set_var) { os << "{"; REPI(itr, set_var) { os << *itr; itr++; if (itr != set_var.end()) os << ", "; itr--; } os << "}"; return os; } // dump #define DUMPOUT cerr void dump_func() { DUMPOUT << endl; } template void dump_func(Head &&head, Tail &&... tail) { DUMPOUT << head; if (sizeof...(Tail) > 0) { DUMPOUT << ", "; } dump_func(move(tail)...); } // chmax (更新「される」かもしれない値が前) template > bool chmax(T &xmax, const U &x, Comp comp = {}) { if (comp(xmax, x)) { xmax = x; return true; } return false; } // chmin (更新「される」かもしれない値が前) template > bool chmin(T &xmin, const U &x, Comp comp = {}) { if (comp(x, xmin)) { xmin = x; return true; } return false; } // ローカル用 #define DEBUG_ #ifdef DEBUG_ #define DEB #define dump(...) \ DUMPOUT << " " << string(#__VA_ARGS__) << ": " \ << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]" \ << endl \ << " ", \ dump_func(__VA_ARGS__) #else #define DEB if (false) #define dump(...) #endif struct AtCoderInitialize { static constexpr int IOS_PREC = 15; static constexpr bool AUTOFLUSH = false; AtCoderInitialize() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cout << fixed << setprecision(IOS_PREC); if (AUTOFLUSH) cout << unitbuf; } } ATCODER_INITIALIZE; /* #endregion */ /* #region ConvWithMint */ #define rep(i, b) REP(i, 0, b) #define si(x) int(x.size()) //size of input must be a power of 2 //output of forward fmt is bit-reversed //output elements are in the range [0,mod*4) //input of inverse fmt should be bit-reversed template void inplace_fmt(vector &f, bool inv) { const int n = si(f); static const int L = 30; static mint g[L], ig[L], p2[L]; if (g[0].v == 0) { rep(i, L) { mint w = -mint::root().pow(((mint::mod - 1) >> (i + 2)) * 3); g[i] = w; ig[i] = w.inv(); p2[i] = mint(1 << i).inv(); } } static constexpr uint mod2 = mint::mod * 2; if (!inv) { int b = n; if (b >>= 1) { //input:[0,mod) rep(i, b) { uint x = f[i + b].v; f[i + b].v = f[i].v + mint::mod - x; f[i].v += x; } } if (b >>= 1) { //input:[0,mod*2) mint p = 1; for (int i = 0, k = 0; i < n; i += b * 2) { REP(j, i, i + b) { uint x = (f[j + b] * p).v; //f[j].v=(f[j].v>= 1) { //input:[0,mod*3) mint p = 1; for (int i = 0, k = 0; i < n; i += b * 2) { REP(j, i, i + b) { uint x = (f[j + b] * p).v; //f[j].v=(f[j].v>= 1) { //input:[0,mod*4) mint p = 1; for (int i = 0, k = 0; i < n; i += b * 2) { REP(j, i, i + b) { uint x = (f[j + b] * p).v; f[j].v = (f[j].v < mod2 ? f[j].v : f[j].v - mod2); f[j + b].v = f[j].v + mint::mod - x; f[j].v += x; } p *= g[__builtin_ctz(++k)]; } } } } else { int b = 1; if (b < n / 2) { //input:[0,mod) mint p = 1; for (int i = 0, k = 0; i < n; i += b * 2) { REP(j, i, i + b) { ull x = f[j].v + mint::mod - f[j + b].v; f[j].v += f[j + b].v; f[j + b].v = x * p.v % mint::mod; } p *= ig[__builtin_ctz(++k)]; } b <<= 1; } for (; b < n / 2; b <<= 1) { mint p = 1; for (int i = 0, k = 0; i < n; i += b * 2) { REP(j, i, i + b / 2) { //input:[0,mod*2) ull x = f[j].v + mod2 - f[j + b].v; f[j].v += f[j + b].v; f[j].v = (f[j].v) < mod2 ? f[j].v : f[j].v - mod2; f[j + b].v = x * p.v % mint::mod; } REP(j, i + b / 2, i + b) { //input:[0,mod) ull x = f[j].v + mint::mod - f[j + b].v; f[j].v += f[j + b].v; //f[j].v=(f[j].v) struct modular { static constexpr uint const &mod = ref.mod; static modular root() { return modular(ref.root); } uint v; //modular(initializer_listls):v(*ls.bg){} modular(ll vv = 0) { s(vv % mod + mod); } modular &s(uint vv) { v = vv < mod ? vv : vv - mod; return *this; } modular operator-() const { return modular() - *this; } modular &operator+=(const modular &rhs) { return s(v + rhs.v); } modular &operator-=(const modular &rhs) { return s(v + mod - rhs.v); } modular &operator*=(const modular &rhs) { v = ull(v) * rhs.v % mod; return *this; } modular &operator/=(const modular &rhs) { return *this *= rhs.inv(); } modular operator+(const modular &rhs) const { return modular(*this) += rhs; } modular operator-(const modular &rhs) const { return modular(*this) -= rhs; } modular operator*(const modular &rhs) const { return modular(*this) *= rhs; } modular operator/(const modular &rhs) const { return modular(*this) /= rhs; } modular pow(int n) const { modular res(1), x(*this); while (n) { if (n & 1) res *= x; x *= x; n >>= 1; } return res; } modular inv() const { return pow(mod - 2); } /*modular inv()const{ int x,y; int g=extgcd(v,mod,x,y); assert(g==1); if(x<0)x+=mod; return modular(x); }*/ friend modular operator+(int x, const modular &y) { return modular(x) + y; } friend modular operator-(int x, const modular &y) { return modular(x) - y; } friend modular operator*(int x, const modular &y) { return modular(x) * y; } friend modular operator/(int x, const modular &y) { return modular(x) / y; } friend ostream &operator<<(ostream &os, const modular &m) { return os << m.v; } friend istream &operator>>(istream &is, modular &m) { ll x; is >> x; m = modular(x); return is; } bool operator<(const modular &r) const { return v < r.v; } bool operator==(const modular &r) const { return v == r.v; } bool operator!=(const modular &r) const { return v != r.v; } explicit operator bool() const { return v; } }; //59501818244292734739283969=5.95*10^25 までの値を正しく計算 //最終的な列の大きさが 2^24 までなら動く //最終的な列の大きさが 2^20 以下のときは,下の 3 つの素数を使ったほうが速い(は?) //VERIFY: yosupo namespace arbitrary_convolution { constexpr modinfo base0{167772161, 3}; //2^25 * 5 + 1 constexpr modinfo base1{469762049, 3}; //2^26 * 7 + 1 constexpr modinfo base2{754974721, 11}; //2^24 * 45 + 1 //constexpr modinfo base0{1045430273,3};//2^20 * 997 + 1 //constexpr modinfo base1{1051721729,6};//2^20 * 1003 + 1 //constexpr modinfo base2{1053818881,7};//2^20 * 1005 + 1 using mint0 = modular; using mint1 = modular; using mint2 = modular; template vc sub(const vc &x, const vc &y, bool same = false) { int n = si(x) + si(y) - 1; int s = 1; while (s < n) s *= 2; vc z(s); rep(i, si(x)) z[i] = x[i].v; inplace_fmt(z, false); if (!same) { vc w(s); rep(i, si(y)) w[i] = y[i].v; inplace_fmt(w, false); rep(i, s) z[i] *= w[i]; } else { rep(i, s) z[i] *= z[i]; } inplace_fmt(z, true); z.resize(n); return z; } template vc multiply(const vc &x, const vc &y, bool same = false) { auto d0 = sub(x, y, same); auto d1 = sub(x, y, same); auto d2 = sub(x, y, same); int n = si(d0); vc res(n); static const mint1 r01 = mint1(mint0::mod).inv(); static const mint2 r02 = mint2(mint0::mod).inv(); static const mint2 r12 = mint2(mint1::mod).inv(); static const mint2 r02r12 = r02 * r12; static const mint w1 = mint(mint0::mod); static const mint w2 = w1 * mint(mint1::mod); rep(i, n) { ull a = d0[i].v; ull b = (d1[i].v + mint1::mod - a) * r01.v % mint1::mod; ull c = ((d2[i].v + mint2::mod - a) * r02r12.v + (mint2::mod - b) * r12.v) % mint2::mod; res[i].v = (a + b * w1.v + c * w2.v) % mint::mod; } return res; } } // namespace arbitrary_convolution using arbitrary_convolution::multiply; template vector add_to_vector(vector &z, T v) { z.push_back(v); return z; } template vector add_to_vector(vector &z, T v, Args... args) { z.push_back(v); add_to_vector(z, args...); return z; } template vector make_vector(T v) { vector z; z.push_back(v); return z; } template vector make_vector(T v, Args... args) { vector z; z.push_back(v); add_to_vector(z, args...); return z; } constexpr modinfo base{1000000007, 0}; using mint = modular; /* #endregion */ /** Problem */ void solve() { ll p, Q; cin >> p >> Q; vll q(Q); cin >> q; // construct a ll n = 2e6 + 11; vc a(n, 0); a[0] = 0; a[1] = 1; REP(i, 2, n) { a[i] = (a[i - 1] * p) + a[i - 2]; } vc ret = arbitrary_convolution::multiply(a, a, true); // dump(result); REP(i, 0, Q) { cout << ret[q[i] - 2] << '\n'; } } /** * エントリポイント. * @return 0. */ int main() { solve(); return 0; }