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