using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApp2
{
    internal class Program
    {
        static long GCD(long a, long b)
        {
            while (b != 0)
            {
                long t = a % b;
                a = b;
                b = t;
            }
            return a;
        }

        static List<long> Djelioce(long n)
        {
            var list = new List<long>();
            for (long i = 1; i * i <= n; i++)
            {
                if (n % i == 0)
                {
                    list.Add(i);
                    if (i * i != n)
                        list.Add(n / i);
                }
            }
            list.Sort();
            return list;
        }

        static void Main(string[] args)
        {
            var p1 = Console.ReadLine().Split().Select(long.Parse).ToArray();
            long n = p1[0];
            int k = (int)p1[1];

            var d = Console.ReadLine().Split().Select(long.Parse).ToArray();
            var djelioceN = Djelioce(n);
            var xorMap = new Dictionary<long, long>();

            foreach (var g in djelioceN)
            {
                long xr = 0;
                foreach (var div in djelioceN)
                {
                    if (div > g) break;
                    if (g % div == 0)
                        xr ^= div;
                }
                xorMap[g] = xr;
            }
            foreach (var x in d)
            {
                long g = GCD(x, n);
                Console.Write(xorMap[g] + " ");
            }
        }
    }
}