求大佬帮忙,关于后两个点对70分,前三点全错
查看原帖
求大佬帮忙,关于后两个点对70分,前三点全错
648660
Name1楼主2022/8/2 13:22
#include<iostream>
#include<cstdio>
#define ll long long
using namespace std;
const int N=5e6+10;
ll n,p,k,a[N],inv[N],s[N],sum[N],pp=1,x,y,ans,tmp;
inline void exgcd(ll a,ll b,ll &x,ll &y)
{
	if(b==0){x=1,y=0;return;}
	exgcd(b,a%b,y,x);
	y-=a/b*x;
}
inline ll read()
{
	ll 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*10+c-48,c=getchar();
	return x*f;
}
signed main()
{
	n=read(),p=read(),k=read();
	s[0]=1,tmp=1;
	for(int i=1;i<=n;i++) a[i]=read(),s[i]=(s[i-1]*a[i])%p;
	exgcd(s[n],p,x,y);sum[n]=x;
	for(int i=n-1;i>0;i--) sum[i]=(sum[i+1]*a[i+1])%p;
	for(int i=1;i<=n;i++)
	{
		tmp=k*tmp%p;
		ans=(ans+sum[i]*s[i-1]%p*tmp%p)%p;
	}
	printf("%lld",ans);
	//return 0;
}
2022/8/2 13:22
加载中...