#include <bits/stdc++.h>
using namespace std;

void unos(vector<long long int> &v, int n)
{
    for(int i=0;i<n;i++)
    {
        cin >> v.at(i);
    }
}
void deli(vector<long long int> &d, int n)
{
    d.push_back(1);
    if(n==1)
        return;
    for(int i=2;i<=n/2;i++)
    {
        if(n%i==0)
            d.push_back(i);
    }
    d.push_back(n);
}
vector<int> binarni(int br)
{
    vector<int> bin;
    while(br / 2 != 0)
    {
        bin.push_back(br%2);
        br /= 2;
    }
    bin.push_back(br%2);

    /*for(int i=0;i<bin.size()/2;i++)
    {
        zamena(bin[i], bin[bin.size()-i-1]);
    }*/

    return bin;
}
int dekadni(vector<int> &v)
{
    int br = 0;

    for(int i=0;i<v.size();i++)
    {
        if(v.at(i) != 0)
        {
            br += pow(2, i);
        }
    }

    return br;
}
vector<int> bin_xor(vector<int> &v, vector<int> &d)
{
    int ma = max(v.size(), d.size()), mi = min(v.size(), d.size());
    vector<int> c(ma);
    for(int i=mi;i<ma;i++)
    {
        if(v.size()<ma)
            v.push_back(0);
        else
            d.push_back(0);
    }

    for(int i=0;i<ma;i++)
    {
        if(v.at(i) + d.at(i) == 1)
            c[i] = 1;
        else
            c[i] = 0;
    }
    return c;
}
void racun(vector<long long int> &delioci, int k, int n)
{
    for(int i=0;i<delioci.size();i++)
    {
        map<int, vector<vector<int>>> mapa;
        vector<long long int> d;
        deli(d, delioci[i]);
        for(auto delilac:d)
        {
            mapa[delilac].push_back(binarni(delilac));
        }
        vector<int> konacni;
        for(auto red:mapa)
        {
            for(auto vektor:red.second)
            {
                konacni = bin_xor(konacni, vektor);
            }
        }
        cout << dekadni(konacni) << " ";
    }
}
int main()
{
    int n, k;
    cin >> n;
    cin >> k;
    vector<long long int> delioci(k);
    unos(delioci, k);
    racun(delioci, k, n);
    return 0;
}