#include <iostream>

int main() {
    int n, k;
    unsigned int arr[1000];
    scanf("%d%d", &n, &k);
    for (int i=0; i<k; i++) {
        scanf("%d", &arr[i]);
    }
    for (int i=0; i<k; i++){
        int temp = 1;
        for (int j=2; j<=arr[i]; j++) {
            if (arr[i]%j==0) {
                temp^=j;
            }
        }
        printf("%d ", temp);
    }
    return 0;
}