#include using namespace std; /*^ debug */ template string to_string(pair p); template string to_string(tuple p); template string to_string(tuple p); string to_string(const string& s) { return '"' + s + '"'; } string to_string(const char* s) { return to_string((string) s); } string to_string(bool b) { return (b ? "true" : "false"); } string to_string(vector v) { bool first = true; string res = "{"; for (int i = 0; i < static_cast(v.size()); i++) { if (!first) { res += ", "; } first = false; res += to_string(v[i]); } res += "}"; return res; } template string to_string(bitset v) { string res = ""; for (size_t i = 0; i < N; i++) { res += static_cast('0' + v[i]); } return res; } template string to_string(A v) { bool first = true; string res = "{"; for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); } res += "}"; return res; } template string to_string(pair p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; } template string to_string(tuple p) { return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")"; } template string to_string(tuple p) { return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")"; } void debug_out() { cerr << endl; } template void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); } #ifdef LOCAL #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #else #define debug(...) 42 #endif /* debug $*/ /*^ generic definitions */ template struct _RecurFun : F { _RecurFun(F&& f) : F(forward(f)) {} template decltype(auto) operator()(Args&&... args) const { return F::operator()(*this, forward(args)...); } }; template decltype(auto) RecurFun(F&& f) { return _RecurFun { forward(f) }; } /* generic definitions $*/ unsigned xor128_x = 123456789, xor128_y = 362436069, xor128_z = 521288629, xor128_w = 88675123; unsigned xor128() { unsigned t = xor128_x ^ (xor128_x << 11); xor128_x = xor128_y; xor128_y = xor128_z; xor128_z = xor128_w; return xor128_w = xor128_w ^ (xor128_w >> 19) ^ (t ^ (t >> 8)); } void generateA(int N, int A[]) { for(int i = 0; i < N; ++ i) A[i] = xor128() % 100003; } int main() { ios::sync_with_stdio(false); const int M = 100003; int N, Q; { cin >> N >> Q; } static int A[M]; { generateA(N, A); } int existsA[M]; { for (int i = 0; i < N; ++i) existsA[A[i]] = 1; } while (Q--) { int q; { cin >> q; } if (q == 0) { cout << 0 << "\n"; } else if (N < 1000) { int best = 0; for (int i = 0; i < N; ++i) { best = max(best, (int) ((int64_t) q * A[i] % M)); } cout << best << "\n"; } else { auto ipow = [](int v, int p, int m) { int r = 1; for (int i = p; i; i >>= 1) { if (i & 1) r = (int64_t) r * v % m; v = (int64_t) v * v % m; } return r; }; int best = M - 1; int invq = ipow(q, M - 2, M); while (!existsA[(int64_t) invq * best % M]) --best; cout << best << "\n"; } } }