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

{
    "EXBSGS扩展拔山盖世": {
        "prefix": "acm-7.1mi",
        "body": [
            "#include<algorithm>",
            "#include<cstdio>",
            "#include<cmath>",
            "#include<map>",
            "#define LL long long",
            "#define Re register int",
            "using namespace std;",
            "int x,y,z;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;",
            "}",
            "inline int mi(Re x,Re k,Re P){",
            "\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 gcd(Re a,Re b){return !b?a:gcd(b,a%b);}",
            "inline void exBSGS(Re x,Re y,Re P){",
            "\tif(y==1){puts(\"0\");return;}",
            "\tRe d=gcd(x,P),tmp=1,t=0;",
            "\twhile(d!=1){",
            "\t\tif(y%d){puts(\"No Solution\");return;}",
            "\t\t++t,y/=d,P/=d,tmp=(LL)tmp*(x/d)%P;",
            "\t\tif(y==tmp){printf(\"%d\\n\",t);return;}",
            "\t\td=gcd(x,P);",
            "\t}",
            "\tRe m=sqrt(P)+1;B.clear();",
            "\tfor(Re b=0,s=y;b<m;++b)B[s]=b,s=(LL)s*x%P;",
            "\tRe s=tmp;tmp=mi(x,m,P);",
            "\tfor(Re a=1;a<=m;++a){",
            "\t\ts=(LL)s*tmp%P;",
            "\t\tif(B.find(s)!=B.end()){printf(\"%d\\n\",a*m-B[s]+t);return;}",
            "\t}",
            "\tputs(\"No Solution\");",
            "}",
            "int main(){",
            "//\tfreopen(\"123.txt\",\"r\",stdin);",
            "\twhile(1){",
            "\t\tin(x),in(y),in(z);",
            "\t\tif(!x&&!y&&!z)break;",
            "\t\texBSGS(x,z,y);",
            "\t}",
            "}",
            ""
        ],
        "description": "插入 EXBSGS扩展拔山盖世"
    }
}