#include #define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++) using namespace std; typedef long long int ll; 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 a[100005]; int b[100005]; int aset[100005] = {}; const ll mod = 100003; ll invmod(ll x) { ll e = mod - 2; ll sum = 1; ll cur = x; while (e > 0) { if (e % 2) { sum = sum * cur % mod; } cur = cur * cur % mod; e /= 2; } return sum; } ll solve(const int *as, ll q) { ll s = mod - 1; while (1) { if (aset[(s * invmod(q)) % mod]) { return s; } s--; } } int main(void){ int n, q; cin >> n >> q; REP(i, 0, q) { cin >> b[i]; } generateA(n, a); if (n >= 400) { REP(i, 0, n) { aset[a[i]] = 1; } REP(i, 0, q) { cout << solve(aset, b[i]) << endl; } return 0; } REP(i, 0, q) { ll ma = 0; REP(j, 0, n) { ma = max(ma, ((ll)a[j] * (ll)b[i]) % mod); } cout << ma << endl; } }