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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    long long n;
    cin >> n;
    vector<long long>prost(n+1, 1);
    prost[1] = 1;
    for (int p = 2; p < n+1; p++) {
        for (int i = p+p; i < n+1; i += p) {
            prost[i] = prost[i] ^ p;
            //cout << i << " " << p << " "<<prost[i]<< endl;
        }
    }
    long long k, c;
    cin >> k;
    for (int i = 0; i < k; i++) {
        cin >> c;
        if (c == 1) {
            cout << c << " "; continue;
        }
        cout << (prost[c] ^ c)<<" ";
    }
    
}