//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.1a^b%m",
        "body": [
            "#pragma GCC optimize(3,\"Ofast\",\"inline\")",
            "#pragma GCC optimize(2)",
            "#include<cstdio>",
            "#include<cctype>",
            "#define LL long long",
            "#define Re register LL",
            "LL i,a,b,m,x,s,phi,flag;char c;",
            "inline LL cf(Re x,Re k){",
            "\tRe s=0;",
            "\twhile(k){",
            "\t\tif(k&1)(s+=x)%=m;",
            "\t\t(x<<=1)%=m,k>>=1;",
            "\t}",
            "\treturn s;",
            "}",
            "int main(){",
            "    scanf(\"%lld%lld\",&a,&m);phi=x=m;",
            "    for(i=2;i*i<=m;++i)if(!(x%i)){phi-=phi/i;while(!(x%i))x/=i;}",
            "    if(x>1)phi-=phi/x;",
            "    while(!isdigit(c=getchar()));",
            "    while(isdigit(c))flag|=((b=(b<<1)+(b<<3)+(c^48))>=phi),b%=phi,c=getchar();",
            "    b+=flag?phi:0;x=1;",
            "    while(b){if(b&1)x=cf(x,a)%m;a=cf(a,a)%m,b>>=1;}",
            "    printf(\"%lld\",x);",
            "}",
            ""
        ],
        "description": "插入 扩展欧拉定理"
    }
}