#include #include #include #include using namespace std; #define REP(i,first,last) for (int i=first;i amari_list(devider, -1); long long pow(long long x, int a) { long long res = 1; if (a > 0) { res = pow(x*x%(devider+1), a/2); if (a % 2 == 1) res = res*x%(devider+1); } return res % (devider+1); } int main(){ cin >> x; cin >> N; int val; long long result = 0; REP(i,0,N) { cin >> val; int target = val % devider; if (amari_list[target] == -1) { int amari = pow(x, target); amari_list[target] = amari; } result += amari_list[target]; result %= (devider+1); } cout<