高级代码(我看不懂)

#include<bits/stdc++.h>
using namespace std;
char buf[1000010],*p1,*p2;
#define gc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1000000,stdin),p1==p2)?EOF:*p1++)
int read(){
    int x=0;
    char c=gc();
    while(c<48) c=gc();
    while(47<c) x=(x<<3)+(x<<1)+(c&15),c=gc();
    return x;
}
int inv[5000010],a[5000010],s[5000010];
int qpow(int a,int k,const int p){
    int ans=1;
    while(k){
        if(k&1) ans=(long long)ans*a%p;
        a=(long long)a*a%p;
        k>>=1;
    }
    return ans;
}
int main(){
    const int n=read(),p=read(),k=read();
    int x=1,tmp,ans=0;
    s[0]=1;
    for(int i=1;i<=n;i++){
        a[i]=read();
        s[i]=(long long)s[i-1]*a[i]%p;
    }
    tmp=qpow(s[n],p-2,p);
    for(int i=n;i;i--){
        inv[i]=(long long)tmp*s[i-1]%p;
    }
    for(int i=1;i<=n;i++){
        x=(long long)x*k%p;
        ans=(ans+(long long)x*inv[i])%p;
    }
    printf("%d",ans);
    return 0;
}
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值