using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using System.Xml.XPath;

namespace ConsoleApp2
{
    internal class Program
    {












        static List<int> Delioci(int a) 
        {
            List<int> l = new List<int>();
            List<int> l1 = Eratosten(a);
            int t = a;
            while (t != 1) 
            {
                foreach (int p in l1) 
                {
                    if (t % p == 0) 
                    {
                        l.Add(p);
                        t /= p;
                        break;
                    }
                }
            }

            return (l);
        }










        static List<int> Eratosten(int n)

        {
            int[] l2 = new int[n];
            bool[] l1 = new bool[n];

            for (int i = 0; i < n; i++)
            {
                l1[i] = true;
            }

            for (int i = 0; i < n; i++)
            {
                l2[i] = i;
            }


            l1[0] = false;
            l1[1] = false;


            for (int i = 0; i < n; i++)
            {
                if (l1[i]) 
                {
                    for (int j = i; j < n; j += i) 
                    {
                        l1[j] = false;
                    }
                    l1[i] = true;
                }
            }
            List <int> l = new List<int>();
            for (int i = 0; i < n; i++)
            {
                if (l1[i]) 
                {
                    l.Add(l2[i]);
                }
            }
            return l;

        }


        static List<int> SviDelioci(int a) 
        {
            List<int> l = new List<int>();
            List<int> l1 = new List<int>();
            l = Delioci(a);

            for (int i = l.Count() - 1; i > 0; i--) 
            {
                l1.Add(l[i] * l[i-1]);
            }

            List<int> l2 = new List<int>();
            l2 = Delioci(a);
            foreach (int o in l2) 
            {
                l1.Add(o);
            }
            l1.Add(1);
            l1.Add(a);
            l1.Sort();

            for (int i = l1.Count() - 1; i > 0; i--)
            {
                if (l1[i] == l1[i - 1]) 
                {
                    l1.Remove(l1[i]);
                }
            }


            return l1;


        }








        static void Main(string[] args)
        {

            
            string[] uzalz = Console.ReadLine().Split(' ');
            string[] uzalz2 = Console.ReadLine().Split(' ');

            

            int n = int.Parse(uzalz[0]);

            int k = int.Parse(uzalz[1]);


            List<int> l = new List<int>();


            for (int i = 0; i < k; i++) 
            {
                int o = int.Parse(uzalz2[i]);

                List<int> l1 = new List<int>();
                List<int> l2 = new List<int>();
                l2 = Eratosten(o+1);

                if (l2.Contains(o))

                {
                    l.Add(1^o);
                }
                else if (o == 1) 
                
                {
                    l.Add(1);
                }
                else
                {
                    l1 = SviDelioci(o);
                    int y = 0;
                    foreach (int a in l1)
                    {
                        y = y ^ a;
                    }
                    l.Add(y);
                }
                
 

                


            }

            foreach (int s in l) 
            {
                Console.Write(s + " ");
            }


            
        }
    }
}