#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;

const int N = 31700;
bool cpl[N];
vector < int > pp;

int main()
{
    FAST;

//    for(int i = 2; i < N; i++)
//    {
//        if(cpl[i] || (long long)i * i > N) continue;
//        for(int j = i * i; j < N; j += i) cpl[j] = true;
//    }
//    for(int i = 2; i < N; i++) if(!cpl[i]) pp.push_back(i);

//    for(auto it : pp) cout << it << " ";
//    cout << "\n";
//    cout << pp.size() << "\n";



    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(b) pr.push_back(v[i].ff);
    }

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




    vector < vector < ll > > del(k + 10);

    for(int i = 0; i < k; i++)
    {
        ll t = v[i].ff;
        del[i].push_back(1ll);
        for(auto it : pr)
        {

            while(t % it == 0)
            {
                t /= it;
                int sizz = del[i].size();
                for(int j = 0; j < sizz; j++) del[i].push_back(del[i][j] * it);
            }
        }
        if(t > 1)
        {
            int sizz = del[i].size();
            for(int j = 0; j < sizz; j++) del[i].push_back(del[i][j] * t);
        }
    }
//    for(int i = 0; i < k; i++)
//    {
//        cout << v[i].ff << ": ";
//        for(auto it : del[i]) cout << it << " ";
//        cout << "\n";
//    }

    vector < int > ans(k);
    for(int i = 0; i < k; i++)
    {
        sort(begin(del[i]), end(del[i]));
        int pos = v[i].ss;
        ans[pos] = 1;
        for(int j = 1; j < del[i].size(); j++) if(del[i][j] != del[i][j - 1]) ans[pos] = (ans[pos]^del[i][j]);
    }

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

    return 0;
}