#include using namespace std; typedef long long int ll; typedef pair pii; typedef vector vi; typedef vector > vii; #define rrep(i, m, n) for(int (i)=(m); (i)<(n); (i)++) #define rep(i, n) for(ll (i)=0; (i)<(n); (i)++) #define rev(i, n) for(ll (i)=(n)-1; (i)>=0; (i)--) #define vrep(i, c) for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++) #define ALL(v) (v).begin(), (v).end() #define mp make_pair #define pb push_back template inline void minup(T1& m, T2 x){ if(m>x) m=static_cast(x); } template inline void maxup(T1& m, T2 x){ if(m(x); } #define INF 10000000000 #define MOD 100003LL #define EPS 1E-9 const int MAX_N = 100003; const int MAX_Q = 100003; int N, Q; int A[MAX_N]; bool exist[MAX_N]; ll q; 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; } ll extgcd(ll a, ll b, ll& x, ll& y) { ll d = a; if(b != 0LL){ d = extgcd(b, a % b, y, x); y -= (a / b) * x; } else{ x = 1LL; y = 0LL; } return d; } ll modInverse(ll a, ll m) { ll x, y; extgcd(a, m, x, y); return (m + x % m) % m; } int main() { cin >> N >> Q; generateA(N, A); rep(i, N) exist[A[i]] = true; while(Q--){ cin >> q; if(q == 0){ cout << 0 << endl; continue; } ll mx = 0LL; if(N < 100 || Q * N < 10000000) rep(i, N) maxup(mx, (A[i] * q) % MOD); else rev(i, N) if(exist[i * modInverse(q, MOD) % MOD]){ mx = i; break; } cout << mx << endl; } return 0; }