#include <bits/stdc++.h>

using namespace std;
using ll = long long;
#define pb push_back

vector<ll> pr;
void fct(ll x, vector<ll> &v, int i = 0) {
    int e = 0;
    for (; i < pr.size(); ++i) {
        if (!(x % pr[i])) {
            while (!(x % pr[i]))    x /= pr[i], e++;
            fct(x, v, i+1);
            break;
        }
    }
    if (i == pr.size()) return;
    int l = v.size()*e;
    for (int j = 0; j < l; ++j) v.pb(v[j]*pr[i]);
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll n, k;
    cin >> n >> k;
    ll a[k+1], b[k+1];
    for (int i = 1; i <= k; ++i) {
        cin >> a[i];
        b[i] = a[i];
    }
    sort(a+1, a+k+1);
    a[0] = 0;
    for (int i = 2; i <= k; ++i) {
        bool ok = 1;
        for (auto x : pr)   ok &= (a[i] % x);
        if (ok) pr.pb(a[i]);
    }
    vector<ll> v = {1};
    for (int i = 1; i <= k; ++i) {
        vector<ll> v = {1};
        fct(b[i], v);
        ll ans = 0;
        for (auto x : v)    ans ^= x;
        cout << ans << ' ';
    }
    cout << '\n';
}