#include <iostream>
#include <vector>
#include <bits/ios_base.h>
#include <cmath>
#include <algorithm>
using namespace std;

int main()
{
    //ios::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    int k;
    cin >> n >> k;
    vector<int> niz(k);
    for (int i=0;i<k;i++) {
     cin >> niz[i];
    }
    for (int i=0;i<k;i++) {
        int xored = 1;
        for (int j = 2;j<=niz[i];j++) {
            if (niz[i]%j==0) xored = xored ^ j;
        }
        cout << xored << " ";
    }

    return 0;
}