{"id":422,"date":"2022-12-26T23:51:13","date_gmt":"2022-12-26T15:51:13","guid":{"rendered":"https:\/\/blog.cirno.fun\/?p=422"},"modified":"2022-12-26T23:51:13","modified_gmt":"2022-12-26T15:51:13","slug":"%e5%bf%ab%e9%80%9f%e5%b9%82%e6%b1%82%e4%b9%98%e6%b3%95%e9%80%86%e5%85%83","status":"publish","type":"post","link":"https:\/\/blog.sssn.tech\/?p=422","title":{"rendered":"\u5feb\u901f\u5e42\u6c42\u4e58\u6cd5\u9006\u5143"},"content":{"rendered":"<p>\u5728\u4ecb\u7ecd\u5feb\u901f\u5e42\u6c42\u4e58\u6cd5\u9006\u5143\u4e4b\u524d\u5148\u4e86\u89e3\u8d39\u9a6c\u5c0f\u5b9a\u7406:<br \/>\n\u5982\u679cp\u662f\u8d28\u6570\uff0c\u4e14a\u4e0d\u662fp\u7684\u500d\u6570\uff0c\u5219<\/p>\n<pre><code class=\"language-katex\">a^{p-1} \\equiv 1(mod \\quad p)<\/code><\/pre>\n<p>\u8fd9\u4e2a\u5b9a\u7406\u5728\u6570\u8bba\u65b9\u9762\u6709\u7740\u91cd\u8981\u5e94\u7528<\/p>\n<p>\u9996\u5148\u7ed9\u51fa\u9006\u5143\u7684\u5b9a\u4e49<br \/>\n\u5bf9\u4e8e\u6574\u6570b,\u5982\u679c<\/p>\n<pre><code class=\"language-katex\">\\exist x \\in Z,\u4f7f\u5f97 \\forall a \\in Z:\\\\\n\u6709\\frac{a}{b} \\equiv ax (mod \\quad p)<\/code><\/pre>\n<p>\u5219\u79f0x\u4e3ab mod p\u7684\u4e58\u6cd5\u9006\u5143<br \/>\n\u4e0a\u8ff0\u6982\u5ff5\u53ef\u80fd\u6709\u4e9b\u7ed5\uff0c\u800c\u4e00\u4e2a\u611f\u6027\u7406\u89e3\u9006\u5143\u7684\u65b9\u6cd5\u5c31\u662f\uff0c<strong>\u9006\u5143\u5c06\u9664\u6cd5\u8f6c\u53d8\u6210\u4e58\u6cd5<\/strong><br \/>\n\u4e5f\u5c31\u662f\u8bf4\uff0c\u5f53\u4e00\u4e2a\u6570\u8981\u9664\u4ee5b\u65f6\uff0c\u6211\u4eec\u53ef\u4ee5\u6c42\u5f97\u4e00\u4e2ax\uff0c\u4f7f\u5f97\u5728mod p\u6761\u4ef6\u4e0b\u9664\u4ee5b\u7684\u7ed3\u679c\u4e0e\u4e58x\u7684\u76f8\u540c\u3002\u6ce8\u610f\uff0c\u4e0a\u8ff0\u5f0f\u5b50\u4e2d\u9664\u6570\u662f\u4efb\u610f\u6574\u6570<\/p>\n<p>b\u7684\u4e58\u6cd5\u9006\u5143\u8bb0\u4f5c<\/p>\n<pre><code class=\"language-katex\">b^{-1}<\/code><\/pre>\n<p>\u8bfb\u4f5cb\u9006\uff0c\u6ce8\u610f\u548c<code class=\"katex-inline\">1\/b<\/code>\u4e0d\u662f\u4e00\u4e2a\u4e1c\u897f<\/p>\n<p><strong>b mod p\u7684\u4e58\u6cd5\u9006\u5143\u5b58\u5728\u7684\u5145\u8981\u6761\u4ef6\u662fb\u4e0ep\u4e92\u8d28<\/strong><\/p>\n<p>\u5728\u4e0a\u5f0f\u4e2d\u4e24\u4fa7\u540c\u65f6\u4e58b\u53ef\u5f97<\/p>\n<pre><code class=\"language-katex\">a \\equiv a b^{-1} b (mod \\quad p)\\\\\nb b^{-1} \\equiv 1(mod \\quad p)<\/code><\/pre>\n<p>\u6b64\u65f6\u7684\u5f62\u5f0f\u548c\u4e0a\u8ff0\u8d39\u9a6c\u5c0f\u5b9a\u7406\u4e00\u81f4\uff0c\u53ef\u4ee5\u5f97\u5230<\/p>\n<pre><code class=\"language-katex\">b ^ {p - 1} \\equiv 1(mod \\quad p) \\\\\nb b ^{p-2} \\equiv 1(mod \\quad p) \\\\\nb^{-1}=b^{p-2}<\/code><\/pre>\n<p>\u6ce8\u610f\u8d39\u9a6c\u5c0f\u5b9a\u7406\u7684\u6761\u4ef6\uff0c<strong>p\u5fc5\u987b\u662f\u8d28\u6570\uff0c\u4e14b\u4e0d\u80fd\u4e3ap\u7684\u500d\u6570<\/strong><\/p>\n<p>\u6240\u4ee5\u4e58\u6cd5\u9006\u5143\u7684\u95ee\u9898\u88ab\u8f6c\u5316\u4e3a\u4e86\u7b80\u5355\u5f62\u5f0f\u7684\u5feb\u901f\u5e42<br \/>\n\u4e0a\u4ee3\u7801<\/p>\n<pre><code class=\"language-cpp\">#include &lt;bits\/stdc++.h&gt;\nusing namespace std;\ntypedef long long ll;\n\nll qmi(ll a, ll k, ll m)\/\/\u5feb\u901f\u5e42\u6a21\u677f\n{\n    \/\/a ^ k % m\n    ll res = 1;\n    while (k)\n    {\n        if(k &amp; 1)   res = res * a % m;\n        k &gt;&gt;= 1;\n        a = a * a % m;\n    }\n    return res;\n}\n\nint main()\n{\n    \/\/ ios::sync_with_stdio(false);\n    int n;\n    scanf(&quot;%d&quot;, &amp;n);\n    while (n--)\n    {\n        ll a, p;\/\/\u6c42a\u6a21p\u7684\u4e58\u6cd5\u9006\u5143\n        scanf(&quot;%lld %lld&quot;, &amp;a, &amp;p);\n        ll res = qmi(a, p - 2, p);\n        if(a % p)\n            printf(&quot;%lld\\n&quot;, res);\n        else\n            puts(&quot;impossible&quot;);\n    }\n    return 0;\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u4ecb\u7ecd\u5feb\u901f\u5e42\u6c42\u4e58\u6cd5\u9006\u5143\u4e4b\u524d\u5148\u4e86\u89e3\u8d39\u9a6c\u5c0f\u5b9a\u7406: \u5982\u679cp\u662f\u8d28\u6570\uff0c\u4e14a\u4e0d\u662fp\u7684\u500d\u6570\uff0c\u5219 [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13,16],"tags":[],"class_list":["post-422","post","type-post","status-publish","format-standard","hentry","category-13","category-16"],"_links":{"self":[{"href":"https:\/\/blog.sssn.tech\/index.php?rest_route=\/wp\/v2\/posts\/422","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.sssn.tech\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.sssn.tech\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.sssn.tech\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.sssn.tech\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=422"}],"version-history":[{"count":0,"href":"https:\/\/blog.sssn.tech\/index.php?rest_route=\/wp\/v2\/posts\/422\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.sssn.tech\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=422"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.sssn.tech\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=422"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.sssn.tech\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=422"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}