using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace _3takmO2025_26
{
    internal class Program
    {
        static List<long> Devisors(long n, long[] d)
        {
            List<long> devisors = new List<long>();
            int ind = 0;
            while (ind<d.Length && d[ind]<=n)
            {
                if (n % d[ind] == 0)
                {
                    devisors.Add(d[ind]);
                }
                ind++;
            }
            return devisors;
        }
        static long XOR(List<long> d)
        {
            long xor = d[0];
            for (int i = 1; i < d.Count; i++)
            {
                xor = xor ^ d[i];
            }
            return xor;
        }
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            long n = long.Parse(input[0]);
            long k = long.Parse(input[1]);
            input = Console.ReadLine().Split();
            long[] d = new long[k];
            long[] d1 = new long[k];
            for(int i = 0; i < k; i++)
            {
                d[i] = long.Parse(input[i]);
                d1[i] = long.Parse(input[i]);
            }
            Array.Sort(d1);
            //long[] res = new long[k];
            for(int i =0; i < k; i++)
            {
                Console.Write(XOR(Devisors(d[i], d1))+" ");
            }
        }
    }
}