//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 的格式要求是 "插入 [该代码片段的中文名]"

{
    "BSGS拔山盖世": {
        "prefix": "acm-7.1可爱的质数",
        "body": [
            "#include<algorithm>",
            "#include<cstdio>",
            "#include<cmath>",
            "#include<map>",
            "#define LL long long",
            "#define Re register int",
            "using namespace std;",
            "const int N=1e5+3;",
            "int x,y,m,P;map<int,int>B;",
            "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;",
            "}",
            "//x^k = y (mod P)",
            "//k = am-b (m=sqrt(P)+1, a\\in[1,m], b\\in[0,m-1])",
            "//(x^m)^a = y x^b (mod P)",
            "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;",
            "}",
            "int main(){",
            "//\tfreopen(\"123.txt\",\"r\",stdin);",
            "\tin(P),in(x),in(y),m=sqrt(P)+1;",
            "\tfor(Re b=0,s=y;b<m;++b)B[s]=b,s=(LL)s*x%P;",
            "\tRe tmp=mi(x,m);",
            "\tfor(Re a=1,s=1;a<=m;++a){",
            "\t\ts=(LL)s*tmp%P;",
            "\t\tif(B.find(s)!=B.end()){printf(\"%d\\n\",a*m-B[s]);return 0;}",
            "\t}",
            "\tputs(\"no solution\");",
            "}",
            ""
        ],
        "description": "插入 BSGS拔山盖世"
    }
}