51nod_1120:机器人走方格 V3

时间:2023-03-09 19:40:47
51nod_1120:机器人走方格 V3

题目链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1120

Catalan数 基础题,ans=C(2n-2,n-2)/n*2

oeis页面:https://oeis.org/A000108

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;

;
LL qpow(LL n,LL k)
{
    LL res=;
    )
    {
        ) res=res*n%mod;
        n=n*n%mod;
    }
    return res;
}
LL inv(LL x)
{
    );
}
LL C(LL n,LL m)
{
    ||n<m) ;
    if(m>n-m) m=n-m;
    LL a=,b=;
    ;i<m;i++)
    {
        a=(n-i)%mod*a%mod;
        b=(+i)%mod*b%mod;
    }
    return a*inv(b)%mod;
}
LL Lucas(LL n,LL k)
{
    ) ;
    return C(n%mod,k%mod)*Lucas(n/mod,k/mod)%mod;
}

int main()
{
    int n;
    while(cin>>n)
        cout<<Lucas(*n-,n-)*inv(n)%mod*%mod<<endl;
}