#include <iostream>
#include <vector>
using namespace std;

int main() 
{
    long long n;
    int k;
    cin >> n >> k;

    vector<long long> d(k);
    for (int i = 0; i < k; i++)
        cin >> d[i];

    if (n == 1)
    {
        for (int i = 0; i < k; i++)
        {
            cout << 1;
            if (i + 1 < k) cout << " ";
        }
        cout << "\n";
        return 0;
    }

    long long rem = n;
    vector<long long> pr;
    vector<int> st;

    while (rem > 1)
    {
        long long mn = 0;

        for (int i = 0; i < k; i++)
        {
            long long x = d[i];
            if (x > 1 && rem % x == 0)
            {
                if (mn == 0 || x < mn)
                    mn = x;
            }
        }

        long long p = mn;
        int e = 0;

        while (rem % p == 0)
        {
            rem /= p;
            e++;
        }

        pr.push_back(p);
        st.push_back(e);
    }

    int m = pr.size();

    vector<int> os(m), kor(m, 1);

    for (int i = 0; i < m; i++)
        os[i] = st[i] + 1;

    for (int i = 1; i < m; i++)
        kor[i] = kor[i - 1] * os[i - 1];

    int sz = 1;
    for (int i = 0; i < m; i++)
        sz *= os[i];

    vector<long long> f(sz, 0), g(sz, 0);
    vector<int> id(k);

    for (int i = 0; i < k; i++)
    {
        long long x = d[i];
        int indeks = 0;

        for (int j = 0; j < m; j++)
        {
            int a = 0;
            while (x % pr[j] == 0)
            {
                x /= pr[j];
                a++;
            }
            indeks += a * kor[j];
        }

        id[i] = indeks;
        f[indeks] = d[i];
    }

    for (int i = 0; i < sz; i++)
        g[i] = f[i];

    for (int dim = 0; dim < m; dim++)
    {
        int korak = kor[dim];
        int blok = korak * os[dim];

        for (int i = 0; i < sz; i += blok)
        {
            for (int j = 0; j < korak; j++)
            {
                for (int t = 1; t < os[dim]; t++)
                {
                    int ind = i + j + t * korak;
                    g[ind] = g[ind] ^ g[ind - korak];
                }
            }
        }
    }

    for (int i = 0; i < k; i++)
    {
        cout << g[id[i]];
        if (i + 1 < k) cout << " ";
    }

    cout << "\n";
    return 0;
}