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

#pragma GCC optimize("O3")
signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0);

    ll n,k;
    cin>>n>>k;
    for(int i=1;i<=k;++i){
        ll x;cin>>x;
        ll ans=0;
        for(ll j=1;j*j<=x;++j){
            if(x%j)continue;
            ans^=j;
            if(j*j!=x)ans^=(x/j);
        }
        cout<<ans<<' ';
    }
}