#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll n,m;
int main(){
    cin>>n>>m;
    vector<ll> divs,org;
    for(ll i=1;i<=m;i++){
        ll x;
        cin>>x;
        org.push_back(x);
    }
    divs=org;
    sort(divs.begin(),divs.end());
    vector<ll> factors;
    for(ll d:divs){
        if(n%d==0 and d!=1){
            factors.push_back(d);
            while(n%d==0)
                n/=d;
        }
    }
    map<ll,ll> res;
    for(auto d:divs)
        res[d]=d;
    for(ll p:factors)
        for(ll x:divs)
            res[x*p]^=res[x];
    for(ll x:org)
        cout<<res[x]<<" ";
    return 0;
}