#include <bits/stdc++.h>
using namespace std;
// typedef long long ll;
inline int read() {
int x = 0, f = 1;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-')
f = -1;
c = getchar();
}
while (c >= '0' && c <= '9')
x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
return x * f;
}
inline long long binpow(long long b, long long p, long long k) {
b %= k;
long long res = 1;
while (p > 0) {
if (p & 1)
res = res * b % k;
b = b * b % k;
p >>= 1;
}
return res;
}
int n, num;
long long dp[1000005], ans = 1, w[1000005], p;
const long long mod = 998244353;
int main() {
cin >> n >> p;
for (int i = 1; i <= n; ++i) {
w[i] = read();
}
for (int i = 1; i <= n; ++i) {
ans *= binpow(p, w[i], mod) + 1;
ans %= mod;
}
cout << ans % mod << endl;
return 0;
}
洛谷P7223 [RC-04] 01 背包(快速幂)
最新推荐文章于 2024-06-05 22:19:18 发布