#include<bits/stdc++.h>
using namespace std;
using ll=long long;

#pragma GCC optimize("O3")

/*map<ll,ll>memo;
ll sol(ll x){
    if(x==1)return 1;
    if(memo[x])return memo[x]-1;
    ll taj=1;
    for(ll i=2;i*i<=x;++i){
        if(!(x%i)){
            taj=i;
            break;
        }
    }
    if(taj==1){
        memo[x]=(x^1)+1;
        return(x^1);
    }
    ll rez=((x^taj)^(sol(x/taj)));
    ll cur=taj;
    while(cur<x){
        if((x/taj)%cur)rez^=cur;
        cur*=taj;
    }
    memo[x]=rez+1;
    return rez;
}*/

ll ans[111111];

signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0);

    ll n,k;
    cin>>n>>k;

    vector<array<ll,2>>lk;
    for(int i=1;i<=k;++i){
        ll x;cin>>x;
        lk.push_back({x,i});
    }

    sort(lk.begin(),lk.end());
    for(int i=0;i<k;++i){
        if(k-i<sqrt(lk[i][0])){
            ll sol=0;
            for(int j=i;j<k;++j){
                if(lk[i][0]%lk[j][0])continue;
                sol^=lk[j][0];
            }
            ans[lk[i][1]]=sol;
        }else{
            ll sol=0;
            for(int j=1;j*j<=lk[i][0];++j){
                if(lk[i][0]%j)continue;
                sol^=j;
                if(j*j!=lk[i][0])sol^=lk[i][0]/j;
            }
            ans[lk[i][1]]=sol;
        }
    }

    for(int i=1;i<=k;++i)
        cout<<ans[i]<<' ';
}