#include <bits/stdc++.h>

using namespace std;

#define ll long long
const int INF=1e9;
const ll LINF=1e18;
#define kec first.second
#define dva first.fi
#define idx second
#define fi first
#define se second
#define Blok pair<pair<long long,long long>,int>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mid ((l+r)/2)
#define sz(a) (int((a).size()))
#define all(a) a.begin(),a.end()
#define endl "\n"
#define pb push_back

void PRINT(int x) {cerr << x;}
void PRINT(ll x) {cerr << x;}
void PRINT(double x) {cerr << x;}
void PRINT(char x) {cerr << '\'' << x << '\'';}
void PRINT(string x) {cerr << '\"' << x << '\"';}
void PRINT(bool x) {cerr << (x ? "true" : "false");}

template<typename T,typename V>
void PRINT(pair<T,V>& x){
    cerr<<"{";
    PRINT(x.fi);
    cerr<<",";
    PRINT(x.se);
    cerr<<"}";
}
template<typename T>
void PRINT(T &x){
    int id=0;
    cerr<<"{";
    for(auto _i:x){
        cerr<<(id++ ? "," : "");
        PRINT(_i);
    }
    cerr<<"}";
}
void _PRINT(){
    cerr<<"]\n";
}
template<typename Head,typename... Tail>
void _PRINT(Head h,Tail... t){
    PRINT(h);
    if(sizeof...(t)) cerr<<", ";
    _PRINT(t...);
}

#define Debug(x...) cerr<<"["<<#x<<"]=["; _PRINT(x)

void Solve(){
    ll N,K; cin>>N>>K;
    vector<ll> d1(K);
    for(int i=0;i<K;i++){
        cin>>d1[i];
    }
    vector<ll> d=d1;
    sort(all(d));
    if(N==1){
        cout<<1<<endl;
        return;
    }
    if(N>1000){
        exit(0);
    }
    vector<ll> prosti; prosti.pb(d[1]);
    unordered_map<ll,vector<ll>> delioci;
    unordered_map<ll,ll> x1;
    delioci[1].pb(1);
    delioci[d[1]].pb(1); delioci[d[1]].pb(d[1]);
    x1[d[1]]=1^d[1];
    x1[1]=1;
    for(int i=2;i<K;i++){
        bool prost=true;
        ll p=-1;
        for(int j=0;j<sz(prosti);j++){
            if(d[i]%prosti[j]==0){
                prost=false;
                p=prosti[j];
                break;
            }
        }
        if(prost){
            prosti.pb(d[i]);
            delioci[d[i]].pb(1); delioci[d[i]].pb(d[i]);
            x1[d[i]]=d[i]^1;
        }
        else{
            ll p_s=1;
            ll D=d[i];
            while(D%p==0){
                p_s*=p;
                D/=p;
            }
            delioci[d[i]]=delioci[d[i]/p];
            vector<ll> v=delioci[d[i]/p_s];
            for(int j=0;j<sz(v);j++){
                delioci[d[i]].pb(p_s*v[j]);
            }
            v=delioci[d[i]];
            ll x=0;
            for(int j=0;j<sz(v);j++){
                x^=v[j];
            }
            x1[d[i]]=x;
        }
    }
    for(int i=0;i<K;i++){
        cout<<x1[d1[i]]<<" ";
    }
    cout<<endl;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t; t=1; //cin>>t;
    while(t--){
        Solve();
    }
    return 0;
}