题目:
题意:
求分式的结果
分析:
我们将分式求和先进行通分,将分母化为
s
(
s
=
∏
i
=
1
n
a
i
)
s(s=\prod_{i=1}^na_i)
s(s=∏i=1nai)
接着我们进行合并,发现需要求逆元的只有分母一项
代码:
#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
#include<cctype>
#include<cmath>
#define LL long long
#define __LZX Mu
using namespace std;
inline LL read() {
LL d=0,f=1;char s=getchar();
while(s<'0'||s>'9'){if(s=='-')f=-1;s=getchar();}
while(s>='0'&&s<='9'){d=d*10+s-'0';s=getchar();}
return d*f;
}
char buf[(int)1e8],*ss=buf;
inline int init(){buf[fread(buf,1,(int)1e8-1,stdin)]='\n';fclose(stdin);return 0;}
const int __START__=init();
inline int readint(){
int d=0;
while(!isdigit(*ss))++ss;
while(isdigit(*ss))d=d*10+(*ss++^'0');
return d;
}
int n,LZX,k;
int a[5000005],q[5000005],h[5000005];
int ksm(int x,int y)
{
int s=1;
while(y)
{
if(y&1) s=(LL)s*x%LZX;
x=(LL)x*x%LZX;y>>=1;
}
return (LL)s;
}
int main()
{
n=readint();LZX=readint();k=readint();
q[0]=h[n+1]=1;
for(int i=1;i<=n;i++) a[i]=readint(),q[i]=(LL)q[i-1]*a[i]%LZX;
for(int i=n;i;i--) h[i]=(LL)a[i]*h[i+1]%LZX;
int kkk=k,ans=0;
for(int i=1;i<=n;i++)
(ans+=(LL)kkk*q[i-1]%LZX*h[i+1]%LZX)%=LZX,kkk=(LL)kkk*k%LZX;
printf("%lld",ans*(LL)ksm(q[n],LZX-2)%LZX);
return 0;
}