#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ff first
#define ss second
#define ll long long
using namespace std;

int koren(ll a)
{
    int l = 1;
    int r = 1000000000;
    while(l < r)
    {
        int mid = (l + r + 1) / 2;
        if((long long)mid * mid <= a) l = mid;
        else r = mid - 1;
    }
    return l;
}


int main()
{
    FAST;

    ll n; cin >> n;
    int k; cin >> k;
    vector < pair < ll, int > > v(k);
    for(int i = 0; i < k; i++) { cin >> v[i].ff; v[i].ss = i; }
    sort(begin(v), end(v));

    vector < ll > pr;

    for(int i = 1; i < k; i++)
    {
        bool b = true;
        for(auto it : pr) if(v[i].ff % it == 0) b = false;

        if(pr.size() > 30)
        {
            cout << v[10000000].ff << "\n";
        }
        if(b) pr.push_back(v[i].ff);
    }

//    for(auto it : pr) cout << it << " ";
//    cout << "\n";

    vector < int > r(k + 3);
    for(int i = 0; i < k; i++)
    {
        int rt = koren(v[i].ff);
        r[i] = rt + 1;
    }

//    for(int i = 0; i < k; i++) cout << r[i] << " ";
//    cout << "\n";


    vector < ll > del(k + 10);
    vector < ll > ans(k);
    for(int i = 0; i < k; i++)
    {
        del.clear();
        ll t = v[i].ff;
        del.push_back(1ll);
        for(auto it : pr)
        {
            while(t % it == 0)
            {
                t /= it;
                int sizz = del.size();
                for(int j = 0; j < sizz; j++) if(del[j] * it < r[i]) del.push_back(del[j] * it);
            }
        }
        if(t > 1)
        {
            int sizz = del.size();
            for(int j = 0; j < sizz; j++) if(del[j] * t < r[i]) del.push_back(del[j] * t);
        }
//        cout << v[i].ff << ": ";
        sort(begin(del), end(del));
//        for(auto it : del) cout << it << " ";
//        cout << "\n";
        int pos = v[i].ss;
        ans[pos] = 0;
        for(int j = 0; j < del.size(); j++)
        {
            if(j == 0 || del[j - 1] != del[j])
            {
                if(v[i].ff / del[j] == del[j]) ans[pos] = (ans[pos]^del[j]);
                else ans[pos] = ((ans[pos]^del[j])^(v[i].ff/del[j]));
            }

        }

    }
//    for(int i = 0; i < k; i++)
//    {
//        cout << v[i].ff << ": ";
//        for(auto it : del[i]) cout << it << " ";
//        cout << "\n";
//    }

    for(int i = 0; i < k; i++) cout << ans[i] << " ";

    return 0;
}