using System; using System.Collections.Generic; using System.Text; using sc = Scanner; using System.Collections; class Program { static void Main(string[] args) { Solve(); #if DEBUG Console.WriteLine("終了するにはなにかキーを押して下さい..."); Console.ReadKey(); #endif } static void Solve() { long x = sc.NextLong(); int n = sc.NextInt(); long answer = 0; int[] quary = sc.NextIntArray(); long[] xPowerTable = new long[30];//log_2(100000000) = oyoso 27 xPowerTable[0] = x; for (int i = 1; i < 30; i++) { xPowerTable[i] = (xPowerTable[i - 1] * xPowerTable[i - 1] )% 1000003; } for (int i = 0; i < n; i++) { long xPowerQuary = 1; int twoPow = 1; for (int j = 0; j < 30; j++) { if ( (quary[i] & twoPow) != 0) { #if DEBUG Console.WriteLine("1 bit remain" + (quary[i] & twoPow)); #endif xPowerQuary = (xPowerQuary * xPowerTable[j])% 1000003; #if DEBUG Console.WriteLine(xPowerQuary); #endif } twoPow *=2; } answer = (answer + xPowerQuary)% 1000003; #if DEBUG Console.WriteLine(xPowerQuary); #endif } Console.WriteLine(answer); #if DEBUG Console.WriteLine("LOCAL CHECK"); #endif } } public static class Scanner { public static string[] NextStrArray() { return Console.ReadLine().Split(' '); } public static long[] NextLongArray() { string[] s = NextStrArray(); long[] a = new long[s.Length]; for (int i = 0; i < a.Length; i++) { a[i] = long.Parse(s[i]); } return a; } public static int[] NextIntArray() { string[] s = NextStrArray(); int[] a = new int[s.Length]; for (int i = 0; i < a.Length; i++) { a[i] = int.Parse(s[i]); } return a; } public static int NextInt() { string tmp = ""; while (true) { string readData = char.ConvertFromUtf32(Console.Read()); if (readData == " " || readData == "\n") break; tmp += readData; } return int.Parse(tmp); } public static double NextDouble() { string tmp = ""; while (true) { string readData = char.ConvertFromUtf32(Console.Read()); if (readData == " " || readData == "\n") break; tmp += readData; } return double.Parse(tmp); } public static long NextLong() { string tmp = ""; while (true) { string readData = char.ConvertFromUtf32(Console.Read()); if (readData == " " || readData == "\n") break; tmp += readData; } return long.Parse(tmp); } public static double[] NextDoubleArray() { string[] s = NextStrArray(); double[] a = new double[s.Length]; for (int i = 0; i < a.Length; i++) { a[i] = double.Parse(s[i]); } return a; } } /// /// ・一般的なデータ構造のオブジェクトT /// ・Icomparableを持った「新たなクラスを生成すること無く」比較方法の動的化 /// を目的とした優先度付きキュー,comparison にCompareToを入れる /// 1回あたりの計算量はPop PushともにO(logn) /// /// class PriorityQueue { ArrayList array; public int Count { get{return array.Count;}} Comparison comparison; /// /// コンストラクタ /// /// Tに対する比較方向を示すデリゲート, (a,b)のとき返り値intに a_int - b_int (a > b) なら昇順,逆なら降順 public PriorityQueue(Comparison comparison) { this.comparison = comparison; array = new ArrayList(); } /// /// ヒープ化されている配列リストに新しい要素を追加する。 /// /// 対象の配列リスト private void PushHeap(T elem) { int n = array.Count; array.Add(elem); while (n != 0) { int i = (n - 1) / 2; // 親と値を入れ替え if (comparison((T)array[n], (T)array[i]) < 0) { T tmp = (T)array[n]; array[n] = array[i]; array[i] = tmp; } n = i; } } /// /// ヒープから指定した値を削除する。 /// /// 対象の配列リスト private T PopHeap() { if (array.Count == 0) throw new IndexOutOfRangeException("要素が0のキューに要素を取り出す命令がおこなわれました"); int n = array.Count - 1; T returnItem = (T)array[0]; array[0] = array[n]; array.RemoveAt(n); for (int i = 0, j; (j = 2 * i + 1) < n; ) { // 値の大きい方の子を選ぶ if ((j != n - 1) && (comparison((T)array[j],(T)array[j+1]) > 0)) j++; // 子と値を入れ替え if (comparison((T)array[i], (T)array[j]) > 0) { T tmp = (T)array[j]; array[j] = array[i]; array[i] = tmp; } i = j; } return returnItem; } /// /// 要素のプッシュ. /// /// 挿入したい要素 public void Push(T elem) { PushHeap(elem); } /// /// 要素をポップ.出したデータはコレクションの中から消える /// /// public T Pop() { return PopHeap(); } /// /// 要素を全て消去する /// public void Clear() { array.Clear(); } }