//Place your snippets for cpp here. Each snippet is defined under a snippet name and has a prefix, body and 
// description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the 
// same ids are connected.
// prefix 的格式要求是 acm-[一级标题编号].[二级标题编号][该代码片段的英文简称]
// description 的格式要求是 "插入 [该代码片段的中文名]"

{
    "卢卡斯定理": {
        "prefix": "acm-7.2mi",
        "body": [
            "#include<cstdio>",
            "#define LL long long",
            "#define Re register int",
            "using namespace std;",
            "const int N=1e5+3;",
            "int n,m,P,T,jc[N];",
            "inline void in(Re &x){",
            "    int f=0;x=0;char c=getchar();",
            "    while(c<'0'||c>'9')f|=c=='-',c=getchar();",
            "    while(c>='0'&&c<='9')x=(x<<1)+(x<<3)+(c^48),c=getchar();",
            "    x=f?-x:x;",
            "}",
            "inline int mi(Re x,Re k){",
            "\tRe s=1;",
            "\twhile(k){",
            "\t\tif(k&1)s=(LL)s*x%P;",
            "\t\tx=(LL)x*x%P,k>>=1;",
            "\t}",
            "\treturn s;",
            "}",
            "inline int inv(Re x){return mi(x,P-2);}",
            "inline int C(Re m,Re n){",
            "\treturn m>n?0:(LL)jc[n]*inv(jc[m])%P*inv(jc[n-m])%P;",
            "}",
            "inline int Lucas(Re m,Re n){",
            "\treturn m==0?1:(LL)Lucas(m/P,n/P)*C(m%P,n%P)%P;",
            "}",
            "int main(){",
            "//\tfreopen(\"123.txt\",\"r\",stdin);",
            "\tin(T);",
            "\twhile(T--){",
            "\t\tin(n),in(m),in(P),jc[0]=1;",
            "\t\tfor(Re i=1;i<=P-1;++i)jc[i]=(LL)jc[i-1]*i%P;",
            "\t\tprintf(\"%d\\n\",Lucas(n,n+m));",
            "\t}",
            "}",
            ""
        ],
        "description": "插入 卢卡斯定理"
    }
}