求助,为什么会CE
查看原帖
求助,为什么会CE
475859
c_z_d楼主2022/5/2 12:17

RT,我的代码如下:

#include<bits/stdc++.h>
using namespace std;
const int N=5e6+1;
int n,p,k,a[N],c[N]={1},ny1[N],ny2[N],s=1,ans;
int power(int a,int b,int c)
{
	int t=1;
	while(b)
	{
		if(b%2)
			t=1ll*t*a%c;
		a=1ll*a*a%c;
		b/=2;
	}
	return t;
}
int main()
{
	scanf("%d%d%d",&n,&p,&k);
	for(int i=1;i<=n;i++)
		scanf("%d",a+i),c[i]=1ll*c[i-1]*a[i]%p;
	ny1[n]=power(c[n],p-2,p);
	for(int i=n;i>=1;i--)
	{
		ny1[i-1]=1ll*a[i]*ny1[i]%p;
		ny2[i]=1ll*c[i-1]*ny1[i]%p;
	}
	for(int i=1;i<=n;i++)
		s=1ll*s*k%p,ans=(ans+1ll*s*ny2[i])%p;
	printf("%d",ans);
	return 0;
}

提交记录:https://www.luogu.com.cn/record/74982544

2022/5/2 12:17
加载中...