全WA求调悬关

P5431 【模板】模意义下的乘法逆元 2

@[houwz351](/user/807266) 建议把代码贴出来(
by PNNNN @ 2024-02-27 21:04:11


@[PNNNN](/user/556975) ```cpp #include<bits/stdc++.h> #define int unsigned long long using namespace std; int read(){ int x=0,f=1; char ch=getchar(); while(!isdigit(ch)){ if(ch=='-'){ f=-1; } ch=getchar(); } while(isdigit(ch)){ x=(x<<1)+(x<<3)+(ch^48); ch=getchar(); } return x*f; } int qpow(int a,int b,int p){ int ans=1%p; for(;b;b>>=1){ if(b&1){ ans=ans*a%p; } a=a*a%p; } return ans; } int n,p,k,a[5000005],s[5000005],sv[5000005],ans; signed main(){ n=read(); p=read(); k=read(); s[0]=1; for(int i=1;i<=n;i++){ a[i]=read(); s[i]=s[i-1]*a[i]%p; } sv[n]=qpow(s[n],p-2,p); for(int i=n-1;i>=1;i--){ sv[i]=sv[i+1]*a[i+1]%p; } int t=k; for(int i=1;i<=n;i++){ ans+=k*s[i-1]*sv[i]%p; k=k*t%p; } cout<<ans%p; return 0; } ```
by houwz351 @ 2024-02-27 21:12:38


@[PNNNN](/user/556975) 求助
by houwz351 @ 2024-02-27 21:13:07


@[houwz351](/user/807266) 对不起对不起,我数学太菜了,帮不了你
by PNNNN @ 2024-02-27 21:24:15


@[PNNNN](/user/556975) 啊啊好吧QwQ
by houwz351 @ 2024-02-27 21:24:55


|