#include <iostream>

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