#include <iostream>
#include<set>
#include<tuple>
#include<algorithm>
#include<map>
#define int long long
#define pii pair<int,int>
#define fi first
#define se second
#define MAXN (int)1e5+5
using namespace std;
int d[MAXN],r[MAXN];
map<int, int>m;
pii ra(int x) {
    if (x == 2) { return { 2,1 }; }
    int o = 1;
    while (x % 2 == 0) {
        x /= 2; o *= 2;
    }
    if (o>1) {
        return { 2,o };
    }
    for (int i = 3; i * i <= x; i+=2) {
        int o = 1;
        while (x % i == 0) {
            o*=i; x /= i;
        }
        if (o>1) { return { i,o }; }
    }
    return { x,1 };
}
void solve() {
    int n, k; cin >> n >> k;
    for (int i = 0; i < k; i++) {
        cin >> d[i];
        int z = 0;
        for (int j = 1; j * j <= d[i]; j++) {
            if (d[i] % j == 0) {
                z ^= j;
                if (d[i] / j != j) {
                    z ^= d[i] / j;
                }
            }
        }
        cout << z << ' ';
    }
    /*sort(d, d + k);
    r[m[1]] = 1;
    for (int i = 1; i < k; i++) {
        pii o = ra(d[i]);
        int a = 1;
        while ((1ll << a) <= o.fi) {
            if ((1ll << a) & o.fi) { r[m[d[i]]] += (r[m[d[i] / o.se]]) * (1ll << a); }
            a++;
        }
        r[m[d[i]]] ^= r[m[d[i]/ o.fi]];
    }
    for (int i = 0; i < k; i++) {
        cout << r[i] << ' ';
    }*/
}
int32_t main()
{
   // cout << ((2 * 2) ^ (3 * 2)) << '\n';
    //cout << (2 ^ 3) * 2;
    ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0);
    solve();
    return 0;
}