#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll findHighestSetBit_GCC(unsigned int n) {
   
    
    return 31 - __builtin_clz(n);
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll n, k;
    cin >> n >> k;
    vector<ll>a(k);
    for(int i = 0; i < k;i++){
        cin >> a[i];
        ll broj;
        if(a[i]!=1){
         broj=a[i]^1;}
        else broj = 1;
        for(int j = 2; j*j <= a[i];j++){
            if(a[i]%j==0){
                broj^=j;
                if(j*j!= a[i])
                    broj^=(a[i]/j);
            }
        }
        cout << broj << ' ';
    }
    
    

    return 0;
}