MLE 应该是数组开多了导致的。
最后统计用快速幂没有 TLE 比较神秘。
但是 WA 是啥呢。。。
#include <bits/stdc++.h>
using lint = long long;
const int N = 5e6 + 10;
#define int long long
int n, k, p;
lint ans, a[N], s[N], t[N], inv[N];
// #define DEBUG 1 // 调试开关
struct IO {
#define MAXSIZE (1 << 20)
#define isdigit(x) (x >= '0' && x <= '9')
char buf[MAXSIZE], *p1, *p2;
char pbuf[MAXSIZE], *pp;
#if DEBUG
#else
IO() : p1(buf), p2(buf), pp(pbuf) {}
~IO() { fwrite(pbuf, 1, pp - pbuf, stdout); }
#endif
char gc() {
#if DEBUG // 调试,可显示字符
return getchar();
#endif
if (p1 == p2) p2 = (p1 = buf) + fread(buf, 1, MAXSIZE, stdin);
return p1 == p2 ? ' ' : *p1++;
}
bool blank(char ch) {
return ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t';
}
template <class T>
void read(T &x) {
double tmp = 1;
bool sign = 0;
x = 0;
char ch = gc();
for (; !isdigit(ch); ch = gc())
if (ch == '-') sign = 1;
for (; isdigit(ch); ch = gc()) x = x * 10 + (ch - '0');
if (ch == '.')
for (ch = gc(); isdigit(ch); ch = gc())
tmp /= 10.0, x += tmp * (ch - '0');
if (sign) x = -x;
}
void read(char *s) {
char ch = gc();
for (; blank(ch); ch = gc());
for (; !blank(ch); ch = gc()) *s++ = ch;
*s = 0;
}
void read(char &c) { for (c = gc(); blank(c); c = gc()); }
void push(const char &c) {
#if DEBUG // 调试,可显示字符
putchar(c);
#else
if (pp - pbuf == MAXSIZE) fwrite(pbuf, 1, MAXSIZE, stdout), pp = pbuf;
*pp++ = c;
#endif
}
template <class T>
void write(T x) {
if (x < 0) x = -x, push('-'); // 负数输出
static T sta[35];
T top = 0;
do {
sta[top++] = x % 10, x /= 10;
} while (x);
while (top) push(sta[--top] + '0');
}
template <class T>
void write(T x, char lastChar) {
write(x), push(lastChar);
}
} io;
lint qpow(lint a, lint b) {
lint ans = 1;
for (; b; b >>= 1) {
if (b & 1) (ans *= a) %= p;
(a *= a) %= p;
}
return ans;
}
void get_inv() {
s[0] = 1;
for (int i = 1; i <= n; ++i)
s[i] = s[i - 1] * a[i] % p;
t[n] = qpow(s[n], p - 2);
for (int i = n - 1; ~i; --i)
t[i] = a[i + 1] * t[i + 1] % p;
for (int i = 1; i <= n; ++i)
inv[i] = s[i - 1] * t[i];
}
signed main() {
io.read(n); io.read(p); io.read(k);
for (int i = 1; i <= n; ++i) io.read(a[i]);
get_inv();
for (int i = 1; i <= n; ++i) {
(ans += qpow(k, i) * inv[i] % p) %= p;
}
io.write(ans, '\n');
return 0;
}