{"id":477,"date":"2020-11-01T12:14:26","date_gmt":"2020-11-01T04:14:26","guid":{"rendered":"http:\/\/123.57.142.208\/?p=477"},"modified":"2021-06-21T19:15:39","modified_gmt":"2021-06-21T11:15:39","slug":"%e4%bf%a1%e6%81%af%e5%ae%89%e5%85%a8%e5%9f%ba%e7%a1%80%e5%ae%9e%e9%aa%8c2","status":"publish","type":"post","link":"http:\/\/43.142.23.155\/?p=477","title":{"rendered":"\u4e2d\u56fd\u5269\u4f59\u5b9a\u7406"},"content":{"rendered":"\n<p>python\u5904\u7406\u5927\u6570\u548c\u6570\u8bba\u7684\u5b59\u5b50\u7b97\u6cd5\u5b9e\u73b0<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"773\" src=\"http:\/\/123.57.142.208\/wp-content\/uploads\/2020\/11\/image-1024x773.png\" alt=\"\" class=\"wp-image-480\" srcset=\"http:\/\/43.142.23.155\/wp-content\/uploads\/2020\/11\/image-1024x773.png 1024w, http:\/\/43.142.23.155\/wp-content\/uploads\/2020\/11\/image-300x226.png 300w, http:\/\/43.142.23.155\/wp-content\/uploads\/2020\/11\/image-768x580.png 768w, http:\/\/43.142.23.155\/wp-content\/uploads\/2020\/11\/image.png 1418w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>#  by EotStxTaB.H\n#  on Sunday.20.11.1\n\nimport math \n\ndef exgcd(a, b):\n    old_s, s = 1, 0\n    old_t, t = 0, 1\n    old_r, r = a, b\n    if b == 0:\n        return 1, 0, a\n    else:\n        while r != 0:\n            q = old_r \/\/ r\n            old_r, r = r, old_r - q * r\n            old_s, s = s, old_s - q * s\n            old_t, t = t, old_t - q * t\n    return old_s\n\n\ndef MjrCal(Mj, mj):\n    s = exgcd(Mj, mj)\n    while s &lt; 1:\n        s += mj\n    return s\n\n\ndef solCal(fileNum):\n    fileName = \"C:\/Users\/15568\/Desktop\/study plus\/\u5bc6\u7801\u5b9e\u9a8c\/e2\/20\u4e2a\u6570\u636e\/{}.txt\".format(fileNum)\n    number = 0\n    with open(fileName) as file:\n        lst = &#91;]\n        for line in file.readlines():\n            lst.append(int(line))\n            number += 1\n    number = number \/\/ 2\n    a = lst&#91;:number]\n    mj = lst&#91;number:]\n\n    flag = True\n\n    for i in range(number - 1):\n        for j in range(i + 1, number):\n            g = math.gcd(mj&#91;i], mj&#91;j])\n            if g != 1:\n                flag = False\n                break\n        else:\n            continue\n        break\n        \n    if not flag:\n        print(\"cannot use the Chinese remainder theorem directly.\")\n        return 0\n\n    Mj = &#91;]\n    m = 1\n    for i in range(number):\n        m *= mj&#91;i]\n    for i in range(number):\n        temp = m \/\/ mj&#91;i]\n        Mj.append(temp)\n\n    Mjr = &#91;]\n    for i in range(number):\n        Mjr.append(MjrCal(Mj&#91;i], mj&#91;i]))\n\n    x = 0\n    for i in range(number):\n        x += Mj&#91;i] * Mjr&#91;i] * a&#91;i]\n    x = x % m\n    print(\"x = {}\".format(x))\n\n\nfor i in range(1, 21):\n    print(i, end=\" : \")\n    solCal(i)<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>python\u5904\u7406\u5927\u6570\u548c\u6570\u8bba\u7684\u5b59\u5b50\u7b97\u6cd5\u5b9e\u73b0<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[11,26],"class_list":["post-477","post","type-post","status-publish","format-standard","hentry","category-10","tag-python","tag-26"],"_links":{"self":[{"href":"http:\/\/43.142.23.155\/index.php?rest_route=\/wp\/v2\/posts\/477","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/43.142.23.155\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/43.142.23.155\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/43.142.23.155\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/43.142.23.155\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=477"}],"version-history":[{"count":1,"href":"http:\/\/43.142.23.155\/index.php?rest_route=\/wp\/v2\/posts\/477\/revisions"}],"predecessor-version":[{"id":574,"href":"http:\/\/43.142.23.155\/index.php?rest_route=\/wp\/v2\/posts\/477\/revisions\/574"}],"wp:attachment":[{"href":"http:\/\/43.142.23.155\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=477"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/43.142.23.155\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=477"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/43.142.23.155\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=477"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}