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

#pragma GCC optimize("O3")
map<ll,ll>mp;
ll ans[111111];

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

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

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

    sort(lk.begin(),lk.end());
    for(int i=0;i<k;++i){
        if(lk[i][0]>1e9){
            ll sol=S1;
            ll T=n/lk[i][0];
            for(int j=1;j*j<=T;++j){
                if(T%j)continue;
                if(lk[i][0]%j)sol^=j;
                if(j*j!=T&&lk[i][0]%(T/j))sol^=T/j;
            }
            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;
            mp[lk[i][0]]=sol;
        }
    }

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