QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#506675#6168. 异构序列码性态问题neilliuCompile Error//C++141.5kb2024-08-05 20:34:162024-08-05 20:34:16

Judging History

你现在查看的是最新测评结果

  • [2024-08-05 20:34:16]
  • 评测
  • [2024-08-05 20:34:16]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
long long ksm(long long a,long long b,long long p){
    long long ans = 1;
    for(; b; b >>= 1){
        if(b & 1) ans = ans * a % p;
        a = a * a % p;
    }
    return ans;
}
long long fac[10000005],infac[10000005],Ca[5000005];
void init(long long n,long long p){
    fac[0] = infac[0] = fac[1] = infac[1] = 1;
    for(int i = 2; i <= n; i++) fac[i] = fac[i-1] * i % p;
    infac[n] = ksm(fac[n],p-2,p);
    for(int i = n-1; i >= 1; i--) infac[i] = infac[i+1] * (i+1) % p;
}
long long C(int x,int y,long long p){
    return fac[x] * infac[y] % p * infac[x-y] % p;
}
void Catalan(int n,long long p){
    Ca[0] = Ca[1] = 1;
    for(int i = 2; i <= n; i++) Ca[i] = Ca[i-1] * (4 * i - 2) * % p * ksm((i+1),p-2,p) % p;
}
int main()
{
    int n; long long p;
    while(~scanf("%d%lld",&n,&p)){
        if(n <= 3){
            printf("0\n");
            continue;
        }
        init(2*n,p);
        Catalan(n,p);
        long long ans = 0;
        n = n-1;
        long long mici = 1;
        for(int i = 0; i <= n; i++){
            long long sum = 1;
            sum = sum * mici % p; mici = mici + mici; if(mici >= p) mici -= p;
            sum = sum * C(n+i,n-i,p) % p;
            sum = sum * (i == 0 ? 1 : Ca[i]) % p;
            if((n-i) & 1) sum = -sum;
            ans = ans + sum;
            if(ans < 0) ans = ans + p;
            if(ans >= p) ans = ans - p;
        }
        printf("%lld\n",(fac[n+1] - ans - ans + p + p) % p);
    }
    return 0;
}

詳細信息

answer.code: In function ‘void Catalan(int, long long int)’:
answer.code:23:65: error: expected primary-expression before ‘%’ token
   23 |     for(int i = 2; i <= n; i++) Ca[i] = Ca[i-1] * (4 * i - 2) * % p * ksm((i+1),p-2,p) % p;
      |                                                                 ^