#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define rep(i,n) FOR(i,0,n) #define REP(i,n) FOR(i,0,n) #define each(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i) #define EACH(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i) #define exist(s,e) ((s).find(e)!=(s).end()) #define dump(x) cerr << #x << " = " << (x) << endl; #define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl; #define deb(x) cerr << #x << " = " << (x) << " , "; #define debl cerr << " (L" << __LINE__ << ")"<< endl; #define sz(s) (int)((s).size()) #define clr(a) memset((a),0,sizeof(a)) #define nclr(a) memset((a),-1,sizeof(a)) #define pb push_back #define INRANGE(x,s,e) ((s)<=(x) && (x)<(e)) #define MP(x,y) make_pair((x),(y)) double pi=3.14159265358979323846; using namespace std; typedef long long ll; typedef pair pii; typedef vector vi; typedef vector vvi; typedef vector vl; typedef vector vvl; typedef vector vd; typedef vector vvd; typedef vector vs; template std::ostream& operator<<(std::ostream& os, const vector& z){ os << "[ "; REP(i,z.size())os << z[i] << ", " ; return ( os << "]" << endl); } template std::ostream& operator<<(std::ostream& os, const set& z){ os << "set( "; EACH(p,z)os << (*p) << ", " ; return ( os << ")" << endl); } template std::ostream& operator<<(std::ostream& os, const map& z){ os << "{ "; EACH(p,z)os << (p->first) << ": " << (p->second) << ", " ; return ( os << "}" << endl); } template std::ostream& operator<<(std::ostream& os, const pair& z){ return ( os << "(" << z.first << ", " << z.second << ",)" ); } double get_time(){ struct timeval tv; gettimeofday(&tv, NULL); return tv.tv_sec + tv.tv_usec*1e-6; } 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, vi&A) { for(int i = 0; i < N; ++ i){ A[i] = ( (ll)xor128() ) % 100003; } } ll mod=100003; struct mint{ ll value; mint():value(0){} mint(ll v):value((v%mod+mod)%mod){} }; mint& operator+=(mint&a, mint b){return a=a.value+b.value;} mint& operator-=(mint&a, mint b){return a=a.value-b.value;} mint& operator*=(mint&a, mint b){return a=a.value*b.value;} mint operator+(mint a, mint b){return a+=b;} mint operator-(mint a, mint b){return a-=b;} mint operator*(mint a, mint b){return a*=b;} mint operator-(mint a){return 0-a;} bool operator==(mint a, mint b){return a.value==b.value;} bool operator!=(mint a, mint b){return a.value!=b.value;} std::ostream& operator<<(std::ostream& os, const mint& m){ return ( os << m.value );} ll extgcd(ll a, ll b, ll &x, ll &y){ ll d=a; if(b!=0){ d=extgcd(b, a%b, y, x); y-=(a/b)*x; } else{ x=1,y=0; } return d; } ll modinverse(ll a, ll b){ ll x,y; ll d=extgcd(a,b, x, y); assert(d==1); return (x%b+b)%b; } mint& operator/=(mint&a, mint b){return a=a.value*modinverse(b.value,mod);} mint operator/(mint a, mint b){return a/=b;} void _main(istream &inp){ bool submit = true; ll N,Q; inp >> N >> Q; vl qs(Q); rep(i,Q) inp >> qs[i]; if(!submit){ rep(i,100003)qs.push_back(i); } double start = get_time(); vi a(N); generateA(N,a); rep(i,10)debug(a[i]); vi h(mod); for(int v:a){ h[v]=1; } ll tot=0; if(N>=2000){ for(ll q:qs){ if(q==0){ cout << 0 << endl; continue; } int v = mod-1; for(; v>=0; v--) { if( h[ (mint(v)/q).value ] ==1)break; } tot += v; if(submit){ cout << v << endl; } } } else{ for(ll q:qs){ ll maxi = -1; for(int v:a) maxi = max(maxi, (q*v)%100003); tot += maxi; if(submit)cout << maxi << endl; } } debug(get_time()-start); debug(tot); } int main(){ if(0){ ifstream ifs("test.txt"); _main(ifs); } else{ _main(cin); } return 0; }