-
Notifications
You must be signed in to change notification settings - Fork 0
/
16.cpp
57 lines (47 loc) · 858 Bytes
/
16.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
using namespace std;
const int MOD = 1000003;
int x;
// x^a mod MOD
ll modpow(int x, int a) {
ll ret = 1;
a %= MOD - 1;
ll y = x;
while (a > 0) {
if (a % 2 == 1) ret = (ret * y) % MOD;
y = y * y % MOD;
a /= 2;
}
return ret;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N;
cin >> x >> N;
int a[N];
rep(i, N) cin >> a[i];
ll ans = 0;
rep(i, N) {
ll m = modpow(x, a[i]);
ans = (ans + m) % MOD;
}
cout << ans << endl;
}