//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.1Miller Rabin",
        "body": [
            "#include<cstdio>",
            "#define LL long long",
            "#define Re register LL",
            "LL n,prime[10]={2,3,5,7,11,13,17,19,23,29};",
            "inline LL cf(Re x,Re k,Re P){",
            "\tRe s=0;",
            "\twhile(k){",
            "\t\tif(k&1)(s+=x)%=P;",
            "\t\t(x<<=1)%=P,k>>=1;",
            "\t}",
            "\treturn s%P;",
            "}",
            "inline LL mi(Re x,Re k,Re P){",
            "\tRe s=1;",
            "    while(k){",
            "    \tif(k&1)s=cf(s,x,P)%P;",
            "    \tx=cf(x,x,P)%P,k>>=1;",
            "    }",
            "    return s%P;",
            "}",
            "inline bool Miller_Rabin(Re x){",
            "    Re s=0,t=x-1;",
            "    if(x==2)return 1;",
            "    if(x<2||!(x&1))return 0;",
            "    while(!(t&1))s++,t>>=1;",
            "    for(Re i=0;i<10&&prime[i]<x;++i){",
            "        Re a=prime[i],b=mi(a,t,x);",
            "        for(Re j=1,k;j<=s;++j){",
            "            k=cf(b,b,x);",
            "            if(k==1&&b!=1&&b!=x-1)return 0;",
            "            b=k;",
            "        }",
            "        if(b!=1)return 0;",
            "    }",
            "    return 1;",
            "}",
            "int main(){",
            "\twhile(scanf(\"%lld\",&n)!=EOF)puts(Miller_Rabin(n)?\"Y\":\"N\");",
            "}",
            ""
        ],
        "description": "插入 判素数"
    }
}