internal class Program
{
    static List<int> nadjiDelioce(int x)
    {
        List<int> list = new List<int>();
        list.Add(1);
        for (int i = 2; i <= x/2; i++)
        {
            if (x % i == 0)
            {
                list.Add(i);
            }
        }
        if(x != 1)
        {
            list.Add(x);
        }
        return list;
    }
    static void Main(string[] args)
    {
        //unos
        string l1 = Console.ReadLine();
        string l2 = Console.ReadLine();
        //ocitavanje
        string[] a1 = l1.Split(" ");
        string[] a2 = l2.Split(" ");

        //l1
        int n = int.Parse(a1[0]);
        int k = int.Parse(a1[1]);
        //l2
        int[] delioci = new int[k];
        for (int i = 0; i < k; i++)
        {
            delioci[i] = int.Parse(a2[i]);
        }


        int[] resenja = new int[k];
        for(int i = 0;i < k; i++)
        {
            List<int> l = nadjiDelioce(delioci[i]);
            int r = 0;
            for (int j = 0; j < l.Count; j++)
            {
                r = r ^ l[j];
            }
            resenja[i] = r;
        }

        for (int i = 0; i < k; i++)
        {
            Console.Write(resenja[i] + " ");
        }
    }
}