比赛 寒假集训2 评测结果 WWWWWAEEEEEEEEEEEEEE
题目名称 组合数问题 最终得分 5
用户昵称 ChenBp 运行时间 3.077 s
代码语言 C++ 内存使用 4.24 MiB
提交时间 2026-02-25 09:55:17
显示代码纯文本
#include <iostream>
#include <cstdio>
using namespace std;
const int N=1e5+5;
typedef long long ll;
ll n,x,p,m;
ll jc[N];
int a[1003];
ll ksm(ll x,int y){
    ll res=1;
    while(y){
        if(y&1) res=res*x%p;
        x=x*x%p;
        y>>=1;
    }
    return res;
}
ll c(ll x,ll y){
    return jc[x]*ksm(jc[y]*jc[x-y]%p,p-2)%p;
}
ll f(int k){
    ll now=0;
    for(int j=0;j<=m;j++){
        now+=a[j]*ksm(k,j);
        now%=p;
    }
    return now;
}
int main(){
    freopen("problem.in","r",stdin);
    freopen("problem.out","w",stdout);
    cin>>n>>x>>p>>m;
    jc[0]=1;
    for(int i=1;i<=N-3;i++){
        jc[i]=(jc[i-1]*i)%p;
    }
    for(int i=0;i<=m;i++){
        cin>>a[i];
    }
    ll ans=0;
    for(int k=0;k<=n;k++){
        ll now=f(k);
        now*=ksm(x,k);now%=p;
        now*=c(n,k);now%=p;
        
        ans+=now;
        ans%=p;
    }
    cout<<ans;
    return 0;
}