#include #include using namespace std; using namespace atcoder; #define rep(i, n) REP(i, 0, n) #define REP(i, s, e) for (ll i = (s); i < (ll)(e); i++) #define repr(i, n) REPR(i, n, 0) #define REPR(i, s, e) for (ll i = (ll)(s - 1); i >= (ll)(e); i--) #define all(r) r.begin(), r.end() #define rall(r) r.rbegin(), r.rend() typedef long long ll; typedef vector vi; typedef vector vl; template bool chmax(T& a, const U& b) { if (a >= b) return false; a = b; return true; } template bool chmin(T& a, const U& b) { if (a <= b) return false; a = b; return true; } void yes_no(bool f, string yes = "Yes", string no = "No") { cout << (f ? yes : no) << "\n"; } 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)); } ll mod_pow(ll a, ll n, ll mod) { ll res = 1; while (n > 0) { if (n & 1LL) (res *= a) %= mod; (a *= a) %= mod; n >>= 1; } return res; } void solve() { int n, q; cin >> n >> q; const ll mod = 100003; vl a(n); rep(i, n) a[i] = xor128() % mod; set st(all(a)); rep(qi, q) { ll x; cin >> x; if (x == 0) { cout << 0 << '\n'; continue; } if (n <= 100) { ll ans = 0; rep(i, n) chmax(ans, a[i] * x % mod); cout << ans << "\n"; } else { ll y = mod_pow(x, mod - 2, mod); repr(i, mod) { if (st.count(i * y % mod)) { cout << i << '\n'; break; } } } } } int main() { cin.tie(0); ios::sync_with_stdio(false); int t = 1; // cin >> t; rep(ti, t) solve(); return 0; }