{"id":226,"date":"2018-12-08T09:56:55","date_gmt":"2018-12-08T09:56:55","guid":{"rendered":"http:\/\/nocriz.com\/?p=226"},"modified":"2021-09-08T20:20:07","modified_gmt":"2021-09-08T12:20:07","slug":"sdoi2013%e9%9a%8f%e6%9c%ba%e6%95%b0%e7%94%9f%e6%88%90%e5%99%a8","status":"publish","type":"post","link":"https:\/\/nocriz.com\/?p=226","title":{"rendered":"[SDOI2013]\u968f\u673a\u6570\u751f\u6210\u5668"},"content":{"rendered":"\n<p><p class=\"ql-center-displayed-equation\" style=\"line-height: 23px;\"><span class=\"ql-right-eqno\"> &nbsp; <\/span><span class=\"ql-left-eqno\"> &nbsp; <\/span><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/nocriz.com\/wp-content\/ql-cache\/quicklatex.com-0ff1495f3708fb3f774ed02d6accb523_l3.png\" height=\"23\" width=\"267\" class=\"ql-img-displayed-equation quicklatex-auto-format\" alt=\"&#92;&#91;&#88;&#95;&#123;&#105;&#43;&#49;&#125;&#32;&#92;&#101;&#113;&#117;&#105;&#118;&#32;&#97;&#42;&#88;&#95;&#123;&#105;&#125;&#43;&#98;&#92;&#32;&#40;&#109;&#111;&#100;&#92;&#32;&#32;&#112;&#41;&#92;&#93;\" title=\"Rendered by QuickLaTeX.com\"\/><\/p><\/p>\n\n\n\n<p><p class=\"ql-center-displayed-equation\" style=\"line-height: 20px;\"><span class=\"ql-right-eqno\"> &nbsp; <\/span><span class=\"ql-left-eqno\"> &nbsp; <\/span><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/nocriz.com\/wp-content\/ql-cache\/quicklatex.com-2f213f3f1ff39dd29976fbc69519dd52_l3.png\" height=\"20\" width=\"155\" class=\"ql-img-displayed-equation quicklatex-auto-format\" alt=\"&#92;&#91;&#32473;&#20986;&#97;&#44;&#98;&#44;&#88;&#95;&#49;&#44;&#27714;&#28385;&#36275;&#88;&#95;&#123;&#105;&#125;&#32;&#61;&#32;&#116;&#30340;&#26368;&#23567;&#105;&#92;&#93;\" title=\"Rendered by QuickLaTeX.com\"\/><\/p><\/p>\n\n\n\n<p>\u8fd9\u9053\u9898\u4e5f\u662f\u4e00\u9053BSGS\u3002<\/p>\n\n\n\n<!--more-->\n\n\n\n<p>\u00a0\u4e0d\u96be\u63a8\u51fa<\/p>\n\n\n\n<p><p class=\"ql-center-displayed-equation\" style=\"line-height: 49px;\"><span class=\"ql-right-eqno\"> &nbsp; <\/span><span class=\"ql-left-eqno\"> &nbsp; <\/span><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/nocriz.com\/wp-content\/ql-cache\/quicklatex.com-4977519277784e3c80e339a3aec4acf7_l3.png\" height=\"49\" width=\"417\" class=\"ql-img-displayed-equation quicklatex-auto-format\" alt=\"&#92;&#91;&#88;&#95;&#123;&#105;&#43;&#49;&#125;&#32;&#43;&#92;&#102;&#114;&#97;&#99;&#123;&#98;&#125;&#123;&#97;&#45;&#49;&#125;&#32;&#92;&#101;&#113;&#117;&#105;&#118;&#32;&#97;&#42;&#40;&#88;&#95;&#123;&#105;&#125;&#43;&#92;&#102;&#114;&#97;&#99;&#123;&#98;&#125;&#123;&#97;&#45;&#49;&#125;&#41;&#92;&#32;&#40;&#109;&#111;&#100;&#92;&#32;&#112;&#41;&#92;&#93;\" title=\"Rendered by QuickLaTeX.com\"\/><\/p><\/p>\n\n\n\n<p><p class=\"ql-center-displayed-equation\" style=\"line-height: 49px;\"><span class=\"ql-right-eqno\"> &nbsp; <\/span><span class=\"ql-left-eqno\"> &nbsp; <\/span><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/nocriz.com\/wp-content\/ql-cache\/quicklatex.com-6b705c03d8b5f6e4ba9cfeaf94c9cab8_l3.png\" height=\"49\" width=\"437\" class=\"ql-img-displayed-equation quicklatex-auto-format\" alt=\"&#92;&#91;&#88;&#95;&#123;&#110;&#125;&#32;&#43;&#92;&#102;&#114;&#97;&#99;&#123;&#98;&#125;&#123;&#97;&#45;&#49;&#125;&#32;&#92;&#101;&#113;&#117;&#105;&#118;&#32;&#97;&#94;&#123;&#110;&#45;&#49;&#125;&#42;&#40;&#88;&#95;&#49;&#43;&#92;&#102;&#114;&#97;&#99;&#123;&#98;&#125;&#123;&#97;&#45;&#49;&#125;&#41;&#92;&#32;&#40;&#109;&#111;&#100;&#92;&#32;&#112;&#41;&#92;&#93;\" title=\"Rendered by QuickLaTeX.com\"\/><\/p><\/p>\n\n\n\n<p>\u90a3\u4e48\u53ea\u8981\u6c42\u6ee1\u8db3<\/p>\n\n\n\n<p><p class=\"ql-center-displayed-equation\" style=\"line-height: 54px;\"><span class=\"ql-right-eqno\"> &nbsp; <\/span><span class=\"ql-left-eqno\"> &nbsp; <\/span><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/nocriz.com\/wp-content\/ql-cache\/quicklatex.com-c9990126e04a67c9c952aba96910931c_l3.png\" height=\"54\" width=\"285\" class=\"ql-img-displayed-equation quicklatex-auto-format\" alt=\"&#92;&#91;&#97;&#94;&#120;&#32;&#92;&#101;&#113;&#117;&#105;&#118;&#32;&#92;&#102;&#114;&#97;&#99;&#123;&#40;&#97;&#45;&#49;&#41;&#116;&#43;&#98;&#125;&#123;&#40;&#97;&#45;&#49;&#41;&#88;&#95;&#49;&#43;&#98;&#125;&#92;&#32;&#40;&#109;&#111;&#100;&#92;&#32;&#112;&#41;&#92;&#93;\" title=\"Rendered by QuickLaTeX.com\"\/><\/p><\/p>\n\n\n\n<p>\u7684\u6700\u5c0fx\u5373\u53ef\uff0c\u8fd9\u4e00\u6b65\u53ef\u4ee5\u4f7f\u7528BSGS\u89e3\u51b3\u3002\u8fd9\u9053\u9898\u8fd8\u6709\u4e00\u4e9b\u7279\u5224\uff0c\u6bd4\u8f83\u7e41\u3002\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;cmath>\n#include &lt;cstdio>\n#include &lt;cstring>\n#include &lt;iostream>\n#include &lt;algorithm>\n#include &lt;unordered_map>\nusing namespace std;\ntypedef long long ll;\ntemplate&lt;typename T> void read(T &amp;x){\n\tx = 0;char ch = getchar();\n\twhile(!isdigit(ch))ch=getchar();\n\twhile(isdigit(ch)){x = x*10+ch-48;ch=getchar();}\n}\nint mod,y,z,blc;\nint mul(int a,int b){return 1ll*a*b%mod;}\nint sq(int x){return 1ll*x*x%mod;}\nint mpow(int a,int b){if(b == 0)return 1;return b&amp;1?mul(a,sq(mpow(a,b\/2))):sq(mpow(a,b\/2));}\nint inv(int x){return mpow(x,mod-2);}\nint exgcd(int a,int b,int &amp;x,int &amp;y){\n\tif(b==0){x=1;y=0;return a;}\n\tint d=exgcd(b,a%b,y,x);y-=1ll*a\/b*x;return d;\n}\nunordered_map&lt;int,int> ump;\nint main() {\n\tint TT,a,b,x1,t;\n\tread(TT);\n\twhile(TT--){\n\t\tread(mod);read(a);read(b);read(x1);read(t);\n\t\ty = a%mod;\n\t\tif(x1 == t){cout&lt;&lt;\"1\\n\";continue;}\n\t\tif(a==0){\n\t\t\tif(b==t)cout&lt;&lt;\"2\\n\";\n\t\t\telse cout&lt;&lt;\"-1\\n\";\n\t\t\tcontinue;\n\t\t}\n\t\tif(a == 1){\n\t\t\tint c = (t-x1+mod)%mod,x,y;\n\t\t\tint d = exgcd(b,mod,x,y);\n\t\t\tif(c%d!=0)cout&lt;&lt;\"-1\\n\";\n\t\t\telse{\n\t\t\t\tx=1ll*x*c\/d%mod;if(x&lt;0)x+=mod;\n\t\t\t\tcout&lt;&lt;x+1&lt;&lt;endl;\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\t\tz = mul(mul(a-1,t)+b,inv(mul(a-1,x1)+b));\n\t\tump.clear();\n\t\tblc = sqrt(mod)+1;\n\t\tint cc = 1;\n\t\tfor(int i=0;i&lt;blc;i++){\n\t\t\tif(!ump.count(cc))ump[cc] = i;\n\t\t\tcc = mul(cc,y);\n\t\t}\n\t\tint st = 1,stinv = 1,invcc = inv(cc),fnd = 0;\n\t\tfor(int po = 0;po&lt;mod;po+=blc,stinv=mul(stinv,invcc)){\n\t\t\tif(!fnd &amp;&amp; ump.count(mul(stinv,z)) &amp;&amp; mpow(y,ump[mul(stinv,z)]+po) == z){\n\t\t\t\tcout&lt;&lt;ump[mul(stinv,z)]+po+1&lt;&lt;endl;\n\t\t\t\tfnd = 1;\n\t\t\t}\n\t\t}\n\t\tif(!fnd) cout&lt;&lt;\"-1\\n\";\n\t}\n\treturn 0;\n}\n<\/code><\/pre>\n ","protected":false},"excerpt":{"rendered":"<p>&nbsp; &nbsp; &nbsp; &nbsp; \u8fd9\u9053\u9898\u4e5f\u662f\u4e00\u9053BSGS\u3002<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,5],"tags":[7],"_links":{"self":[{"href":"https:\/\/nocriz.com\/index.php?rest_route=\/wp\/v2\/posts\/226"}],"collection":[{"href":"https:\/\/nocriz.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nocriz.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nocriz.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/nocriz.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=226"}],"version-history":[{"count":1,"href":"https:\/\/nocriz.com\/index.php?rest_route=\/wp\/v2\/posts\/226\/revisions"}],"predecessor-version":[{"id":752,"href":"https:\/\/nocriz.com\/index.php?rest_route=\/wp\/v2\/posts\/226\/revisions\/752"}],"wp:attachment":[{"href":"https:\/\/nocriz.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=226"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nocriz.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=226"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nocriz.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=226"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}