崩了。
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define maxn 5000005
int n,p,k,a[maxn],pre[maxn],suf[maxn];
ll ans;
inline int exgcd(int a,int b,int &x,int &y)
{
if(b==0)
{
x=1,y=0;
return a;
}
int d=exgcd(b,a%b,x,y);
int t=x;
x=y;
y=t-(a/b)*y;
return d;
}
inline int inv(const int &val)
{
int x,y;
exgcd(val,p,x,y);
return (x%p+p)%p;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
cin >> n >> p >> k;
pre[0]=suf[0]=1;
for(int i=1;i<=n;++i)
{
cin >> a[i];
pre[i]=((ll)pre[i-1]*a[i])%p;
}
for(int i=1;i<=n;++i)
suf[i]=((ll)suf[i-1]*a[n-i+1])%p;
for(int i=1,kk=k;i<=n;++i,kk=(kk*k)%p)
ans=(ans+(((ll)kk*pre[i-1]%p)*suf[n-i]))%p;
cout << ((ll)ans*inv(pre[n]))%p << endl;
return 0;
}
很可能是某些非常傻逼的错误。