#include <bits/stdc++.h>

using namespace std;

#define int long long
#define MAXN 100001

int n,k;
vector<pair<int,int>> vec;
map<int,int> position;
int answer[MAXN];

int32_t main()
{
    ios_base::sync_with_stdio(false);ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    cin>>n>>k;for (int i=1;i<=k;i++) {int x;cin>>x;vec.push_back({x,i});}
    sort(vec.begin(),vec.end());for (pair<int,int> p:vec) position[p.first]=p.second;
    if (n<=10000000)
    {
        for (int i=0;i<k;i++)
        {
            int num=vec[i].first,poz=vec[i].second;
            for (int j=0;j<k;j++)
            {
                if (num%vec[j].first==0) answer[poz]^=vec[j].first;
            }
        }
        for (int i=1;i<=k;i++) cout<<answer[i]<<" ";
        cout<<endl;return 0;
    }
    for (int i=0;i<k;i++)
    {
        int num=vec[i].first,poz=vec[i].second;
        if (num==1) {answer[poz]=1;continue;}
        answer[poz]=1^num;
        for (int p=2;p*p<=num;p++)
        {
            if (num%p!=0) continue;
            int number1=p,number2=num/p;
            if (num==p*p) answer[poz]^=p;
            else answer[poz]^=number1^number2;
        }
    }
    for (int i=1;i<=k;i++) cout<<answer[i]<<" ";
    cout<<endl;return 0;
}