{"id":421,"date":"2022-12-26T20:05:50","date_gmt":"2022-12-26T12:05:50","guid":{"rendered":"https:\/\/blog.cirno.fun\/?p=421"},"modified":"2022-12-26T20:05:50","modified_gmt":"2022-12-26T12:05:50","slug":"%e7%ba%bf%e6%80%a7%e5%90%8c%e4%bd%99%e6%96%b9%e7%a8%8b","status":"publish","type":"post","link":"https:\/\/blog.sssn.tech\/?p=421","title":{"rendered":"\u6269\u5c55\u6b27\u51e0\u91cc\u5f97\u7b97\u6cd5\u6c42\u7ebf\u6027\u540c\u4f59\u65b9\u7a0b"},"content":{"rendered":"<p>\u672c\u8282\u9700\u8981\u524d\u7f6e\u77e5\u8bc6<strong>\u6269\u5c55\u6b27\u51e0\u91cc\u5f97\u7b97\u6cd5<\/strong>\uff0c\u4e0d\u4e86\u89e3\u7684\u53ef\u4ee5\u5148\u770b\u6211\u7684\u4e0a\u4e00\u7bc7\u535a\u6587<br \/>\n<a href=\"https:\/\/blog.cirno.fun\/?p=420\" title=\"\u88f4\u8700\u5b9a\u7406\u4e0e\u6269\u5c55\u6b27\u51e0\u91cc\u5f97\u7b97\u6cd5\">\u88f4\u8700\u5b9a\u7406\u4e0e\u6269\u5c55\u6b27\u51e0\u91cc\u5f97\u7b97\u6cd5<\/a><\/p>\n<p>\u5148\u4ecb\u7ecd\u540c\u4f59\u65b9\u7a0b<\/p>\n<pre><code class=\"language-katex\">ax\\equiv b(mod \\quad m)<\/code><\/pre>\n<p>\u8be5\u65b9\u7a0b\u4e2d\uff0cx\u662f\u672a\u77e5\u6570\uff0c\u5176\u4f59\u4e3a\u5df2\u77e5\uff0c\u542b\u4e49\u662f\u6c42x\uff0c\u4f7f\u5f97<\/p>\n<pre><code class=\"language-katex\">ax \\quad mod \\quad m =b<\/code><\/pre>\n<p>\u8be5\u65b9\u7a0b\u53ef\u4ee5\u65e0\u89e3\uff0c\u6216\u8005\u6709\u591a\u89e3<\/p>\n<p>\u4e0a\u5f0f\u4e0d\u96be\u5199\u6210<\/p>\n<pre><code class=\"language-katex\">ax = my+b,y\\in \\mathbb{Z} \u2460<\/code><\/pre>\n<p>\u89c2\u5bdf\u53ef\u4ee5\u53d1\u73b0\u5f62\u5f0f\u975e\u5e38\u50cf\u6269\u5c55\u6b27\u51e0\u91cc\u5f97\u7b97\u6cd5\u4e2d\u6240\u6c42\u7684\u65b9\u7a0b<\/p>\n<pre><code class=\"language-katex\">ax+by=gcd(a,b)\u2461<\/code><\/pre>\n<p>\u5c06\u2460\u5f0f\u79fb\u9879\u6574\u7406\u6210\u548c\u2461\u76f8\u540c\u7684\u5f62\u5f0f<\/p>\n<pre><code class=\"language-katex\">ax + my&#039;=b,y&#039;=-y<\/code><\/pre>\n<p>\u7531\u4e0a\u8282\u53ef\u77e5\uff0c\u8be5\u65b9\u7a0b\u6709\u89e3\u7684\u5145\u8981\u6761\u4ef6\u662f<\/p>\n<pre><code class=\"language-katex\">gcd(a,b) \\mid b<\/code><\/pre>\n<p>\u6240\u4ee5\u5f53\u8be5\u6761\u4ef6\u6210\u7acb\u65f6\uff0c\u9898\u76ee\u6240\u6c42\u7684x\u662f\u65b9\u7a0b\u4e2dx\u6269\u5927b\/d\u500d\u7684\u6570\uff0c\u800c\u4e0d\u6210\u7acb\u5c31\u76f4\u63a5\u8f93\u51faimposs<\/p>\n<pre><code class=\"language-cpp\">#include &lt;bits\/stdc++.h&gt;\nusing namespace std;\ntypedef long long LL;\n\n\/\/ax+by=gcd\nLL exgcd(LL a, LL b, LL &amp;x, LL &amp;y)\n{\n    if(!b)\n    {\n        x = 1; y = 0;\n        return a;\n    }\n    LL res = exgcd(b, a % b, y, x);\n    y -= (a \/ b) * x;\n    return res;\n}\n\nint main()\n{\n    int n;\n    scanf(&quot;%d&quot;, &amp;n);\n    while (n--)\n    {\n        LL a, b, m;\n        scanf(&quot;%lld %lld %lld&quot;,&amp;a, &amp;b, &amp;m);\n        LL x, y;\n        LL d = exgcd(a, m, x, y);\n        if (b % d)\n            puts(&quot;impossible&quot;);\n        else\n            printf(&quot;%lld\\n&quot;, (long long) (x * b \/ d) % m);\n    }\n    return 0;\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u672c\u8282\u9700\u8981\u524d\u7f6e\u77e5\u8bc6\u6269\u5c55\u6b27\u51e0\u91cc\u5f97\u7b97\u6cd5\uff0c\u4e0d\u4e86\u89e3\u7684\u53ef\u4ee5\u5148\u770b\u6211\u7684\u4e0a\u4e00\u7bc7\u535a\u6587 \u88f4\u8700\u5b9a\u7406\u4e0e\u6269\u5c55 [&#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-421","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\/421","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=421"}],"version-history":[{"count":0,"href":"https:\/\/blog.sssn.tech\/index.php?rest_route=\/wp\/v2\/posts\/421\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.sssn.tech\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=421"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.sssn.tech\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=421"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.sssn.tech\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=421"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}