{"id":13940,"date":"2021-05-30T23:14:46","date_gmt":"2021-05-30T23:14:46","guid":{"rendered":"https:\/\/club.informatix.co.jp\/?p=13940"},"modified":"2025-05-16T10:45:38","modified_gmt":"2025-05-16T01:45:38","slug":"python%e3%81%a7%e6%95%b0%e8%ab%96%ef%bc%81%e6%9c%aa%e8%a7%a3%e6%b1%ba%e5%95%8f%e9%a1%8c%e3%80%8c%e3%82%b3%e3%83%a9%e3%83%83%e3%83%84%e3%83%bb%e8%a7%92%e8%b0%b7%e4%ba%88%e6%83%b3%e3%80%8d%ef%bd%9cpytho","status":"publish","type":"post","link":"https:\/\/club.informatix.co.jp\/?p=13940","title":{"rendered":"Python\u3067\u6570\u8ad6\uff01\u672a\u89e3\u6c7a\u554f\u984c\u300c\u30b3\u30e9\u30c3\u30c4\u30fb\u89d2\u8c37\u4e88\u60f3\u300d\uff5cPython\u3067\u6570\u5b66\u3092\u5b66\u307c\u3046\uff01 \u7b2c9\u56de"},"content":{"rendered":"\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_83 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">\u76ee\u6b21<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-6a1344760efa9\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-6a1344760efa9\" checked aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/club.informatix.co.jp\/?p=13940\/#%E3%82%B3%E3%83%A9%E3%83%83%E3%83%84%E4%BA%88%E6%83%B3\" >\u30b3\u30e9\u30c3\u30c4\u4e88\u60f3<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/club.informatix.co.jp\/?p=13940\/#%E3%82%B3%E3%83%A9%E3%83%83%E3%83%84%E3%83%BB%E3%82%B7%E3%83%BC%E3%82%AF%E3%82%A8%E3%83%B3%E3%82%B9%E3%81%AE%E3%82%B9%E3%83%86%E3%83%83%E3%83%97%E6%95%B0%E3%81%AB%E6%B3%A8%E7%9B%AE%E3%81%99%E3%82%8B\" >\u30b3\u30e9\u30c3\u30c4\u30fb\u30b7\u30fc\u30af\u30a8\u30f3\u30b9\u306e\u30b9\u30c6\u30c3\u30d7\u6570\u306b\u6ce8\u76ee\u3059\u308b<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/club.informatix.co.jp\/?p=13940\/#%E3%83%97%E3%83%AD%E3%82%B0%E3%83%A9%E3%83%A0%E3%80%8Ccolgpy%E3%80%8D\" >\u30d7\u30ed\u30b0\u30e9\u30e0\u300ccolg.py\u300d<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/club.informatix.co.jp\/?p=13940\/#%E6%99%82%E5%88%86%E7%A7%92%E8%A1%A8%E7%A4%BA%E3%82%92%E8%A1%8C%E3%81%86datetime%E3%83%A2%E3%82%B8%E3%83%A5%E3%83%BC%E3%83%AB\" >\u6642\u5206\u79d2\u8868\u793a\u3092\u884c\u3046datetime\u30e2\u30b8\u30e5\u30fc\u30eb<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/club.informatix.co.jp\/?p=13940\/#%E8%A8%88%E7%AE%97%E8%AA%A4%E5%B7%AE%E3%82%92%E9%98%B2%E3%81%90decimal%E3%83%A2%E3%82%B8%E3%83%A5%E3%83%BC%E3%83%AB\" >\u8a08\u7b97\u8aa4\u5dee\u3092\u9632\u3050decimal\u30e2\u30b8\u30e5\u30fc\u30eb<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/club.informatix.co.jp\/?p=13940\/#%E3%83%97%E3%83%AD%E3%82%B0%E3%83%A9%E3%83%A0%E3%80%8Ccolggy%E3%80%8D%E3%81%AE%E5%AE%9F%E8%A1%8C%E7%B5%90%E6%9E%9C\" >\u30d7\u30ed\u30b0\u30e9\u30e0\u300ccolg.gy\u300d\u306e\u5b9f\u884c\u7d50\u679c<\/a><\/li><\/ul><\/nav><\/div>\n<h2><span class=\"ez-toc-section\" id=\"%E3%82%B3%E3%83%A9%E3%83%83%E3%83%84%E4%BA%88%E6%83%B3\"><\/span>\u30b3\u30e9\u30c3\u30c4\u4e88\u60f3<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><a href=\"https:\/\/club.informatix.co.jp\/?p=13605\" target=\"_blank\" rel=\"noopener\">\u524d\u56de<\/a>\u306f\u30b3\u30e9\u30c3\u30c4\u30fb\u89d2\u8c37\u4e88\u60f3\u3092\u7d39\u4ecb\u3057\u3001\u4e88\u60f3\u3092\u691c\u8a3c\u3059\u308b\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u30b3\u30fc\u30c7\u30a3\u30f3\u30b0\u3057\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n<p>\u4efb\u610f\u306e\u81ea\u7136\u6570\u306b\u5bfe\u3057\u3001\u5076\u6570\u306a\u30892\u3067\u5272\u308a\u3001\u5947\u6570\u306a\u30893\u500d\u30571\u3092\u8db3\u3059\u3001\u3068\u30448\u3046\u30b7\u30f3\u30d7\u30eb\u306a\u30a2\u30eb\u30b4\u30ea\u30ba\u30e0\u306b\u3088\u3063\u3066\u751f\u6210\u3055\u308c\u308b\u6570\u5217\u2500\u2500\u30b3\u30e9\u30c3\u30c4\u30fb\u30b7\u30fc\u30af\u30a8\u30f3\u30b9\u306f\u5fc5\u305a1\u3067\u7d42\u308f\u308b\u3060\u308d\u3046\u3002<\/p>\n<p>\u3053\u308c\u304c\u30b3\u30e9\u30c3\u30c4\u30fb\u89d2\u8c37\u4e88\u60f3\u3067\u3059\u3002<\/p>\n<p>1937\u5e74\u306b\u30ed\u30fc\u30bf\u30fc\u30fb\u30b3\u30e9\u30c3\u30c4\u306b\u3088\u3063\u3066\u63d0\u8d77\u3055\u308c\u3066\u4ee5\u6765\u3001\u4eca\u65e5\u307e\u3067\u8a3c\u660e\u3055\u308c\u3066\u3044\u306a\u3044\u6570\u8ad6\u306e\u672a\u89e3\u6c7a\u554f\u984c\u3067\u3059\u3002<\/p>\n<p><a href=\"https:\/\/club.informatix.co.jp\/?p=13605\" target=\"_blank\" rel=\"noopener\">\u524d\u56de<\/a>\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u300ccol.gy\u300d\u3067\u306f\u6b21\u306e4\u3064\u3092\u7b97\u51fa\u3057\u307e\u3059\u3002<\/p>\n<ol>\n<li>\u4e0e\u3048\u3089\u308c\u305fn\u306b\u5bfe\u3059\u308b\u30b3\u30e9\u30c3\u30c4\u30fb\u30b7\u30fc\u30af\u30a8\u30f3\u30b9\u751f\u6210<\/li>\n<li>a\u2266n\u2266b\u306b\u5bfe\u3059\u308b\u30b3\u30e9\u30c3\u30c4\u30fb\u30b7\u30fc\u30af\u30a8\u30f3\u30b9\u751f\u6210<\/li>\n<li>a\u2266n\u2266b\uff08\u6570\u5f0f\u5165\u529b\u53ef\uff09\u306b\u5bfe\u3059\u308b\u30b9\u30c6\u30c3\u30d7\u6570\u8868\u793a\uff0b\u6642\u9593\u8a08\u6e2c<\/li>\n<li>\u30b3\u30e9\u30c3\u30c4\u30fb\u30a2\u30eb\u30b4\u30ea\u30ba\u30e0\u3092\u5909\u3048\u305f\u5834\u5408<\/li>\n<\/ol>\n<p>\u3044\u304f\u3064\u3082\u306e\u81ea\u7136\u6570\u306b\u5bfe\u3057\u3066\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u5b9f\u884c\u3055\u305b\u3066\u5b9f\u9a13\u3092\u884c\u3063\u3066\u307f\u308b\u3053\u3068\u3067\u3001\u4e88\u60f3\u306e\u691c\u8a0e\u3068\u540c\u6642\u306b\u30b3\u30e9\u30c3\u30c4\u30fb\u30b7\u30fc\u30af\u30a8\u30f3\u30b9\u306e\u6319\u52d5\u306b\u3064\u3044\u3066\u5206\u304b\u3063\u3066\u304f\u308b\u3053\u3068\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<h2><span class=\"ez-toc-section\" id=\"%E3%82%B3%E3%83%A9%E3%83%83%E3%83%84%E3%83%BB%E3%82%B7%E3%83%BC%E3%82%AF%E3%82%A8%E3%83%B3%E3%82%B9%E3%81%AE%E3%82%B9%E3%83%86%E3%83%83%E3%83%97%E6%95%B0%E3%81%AB%E6%B3%A8%E7%9B%AE%E3%81%99%E3%82%8B\"><\/span>\u30b3\u30e9\u30c3\u30c4\u30fb\u30b7\u30fc\u30af\u30a8\u30f3\u30b9\u306e\u30b9\u30c6\u30c3\u30d7\u6570\u306b\u6ce8\u76ee\u3059\u308b<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>n\u304c27\u306e\u5834\u5408\u306b1\u306b\u81f3\u308b\u307e\u3067111\u30b9\u30c6\u30c3\u30d7\u304b\u304b\u308a\u307e\u3059\u3002<\/p>\n<p>\u305d\u3053\u3067\u3001n\u306e\u5024\u3092\u5927\u304d\u304f\u3057\u3066\u3044\u304f\u3068\u30b9\u30c6\u30c3\u30d7\u6570\u304c\u3069\u306e\u3088\u3046\u306b\u5927\u304d\u304f\u306a\u308b\u306e\u304b\u304c\u6c17\u306b\u306a\u308b\u3067\u3057\u3087\u3046\u3002\u30d7\u30ed\u30b0\u30e9\u30e0\u300ccol.gy\u300d\u306e3\u3092\u9078\u629e\u3059\u308b\u3053\u3068\u3067\u30b9\u30c6\u30c3\u30d7\u6570\u3060\u3051\u3092\u77e5\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>\u6b21\u306f\u8a08\u7b97\u7d50\u679c\u306e1\u4f8b\u3067\u3059\u3002<\/p>\n<p>\u4e88\u60f3\u306b\u53cd\u3057\u3001n\u3092\u5927\u304d\u304f\u3057\u3066\u3082\u30b9\u30c6\u30c3\u30d7\u6570\u306f\u3055\u307b\u3069\u5927\u304d\u304f\u306f\u306a\u308a\u307e\u305b\u3093\u300211\u6841\u306en\uff0810\u306e10\u4e57\uff09\u306b\u5bfe\u3057\u3066\u3082\u30b9\u30c6\u30c3\u30d7\u6570\u306f\u9ad8\u3005100\u53f0\u3067\u3059\u3002<\/p>\n<p><img decoding=\"async\" class=\"aligncenter size-full wp-image-13943\" src=\"https:\/\/club.informatix.co.jp\/wp-content\/uploads\/2021\/05\/20210529-1.jpg\" alt=\"\" width=\"534\" height=\"439\" srcset=\"https:\/\/club.informatix.co.jp\/wp-content\/uploads\/2021\/05\/20210529-1.jpg 534w, https:\/\/club.informatix.co.jp\/wp-content\/uploads\/2021\/05\/20210529-1-300x247.jpg 300w\" sizes=\"(max-width: 534px) 100vw, 534px\" \/><\/p>\n<p>\u305d\u3053\u3067\u3001a\u2266n\u2266b\u306en\u306b\u5bfe\u3059\u308b\u30b3\u30e9\u30c3\u30c4\u30fb\u30b7\u30fc\u30af\u30a8\u30f3\u30b9\u306e\u30b9\u30c6\u30c3\u30d7\u6570\u306e\u6700\u5927\u5024\u3092\u6c42\u3081\u308b\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u30b3\u30fc\u30c7\u30a3\u30f3\u30b0\u3057\u3066\u307f\u307e\u3059\u3002<\/p>\n<p>\u3055\u3089\u306b\u3001a\u2266n\u2266b\u306en\u306b\u5bfe\u3059\u308b\u30b9\u30c6\u30c3\u30d7\u6570\u306e\u983b\u5ea6\u3092\u8abf\u3079\u308b\u305f\u3081\u3001\u30b0\u30e9\u30d5\u3092\u63cf\u304f\u30d7\u30ed\u30b0\u30e9\u30e0\u3082\u30b3\u30fc\u30c7\u30a3\u30f3\u30b0\u3057\u3066\u307f\u307e\u3059\u3002<\/p>\n<h2><span class=\"ez-toc-section\" id=\"%E3%83%97%E3%83%AD%E3%82%B0%E3%83%A9%E3%83%A0%E3%80%8Ccolgpy%E3%80%8D\"><\/span>\u30d7\u30ed\u30b0\u30e9\u30e0\u300ccolg.py\u300d<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>&gt;&gt;&gt; # colg.py<br \/>\n&gt;&gt;&gt; # \u30b9\u30c6\u30c3\u30d7\u6570\uff08\u6700\u5927\u30b9\u30c6\u30c3\u30d7\u6570\uff09\u3068\u983b\u5ea6\u306e\u30b0\u30e9\u30d5\u63cf\u753b<br \/>\n&gt;&gt;&gt; import numpy as np\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000# \u914d\u5217\u3092\u6271\u3046\u6570\u5024\u8a08\u7b97\u30e9\u30a4\u30d6\u30e9\u30eaNumPy<br \/>\n&gt;&gt;&gt; import matplotlib.pyplot as plt \u3000\u3000\u3000\u3000\u3000# \u30b0\u30e9\u30d5\u63cf\u753b\u30e9\u30a4\u30d6\u30e9\u30eamatplotlib<br \/>\n&gt;&gt;&gt; import japanize_matplotlib\u3000\u3000\u3000\u3000\u3000\u3000\u3000# matplotlib\u306e\u65e5\u672c\u8a9e\u5316<br \/>\n&gt;&gt;&gt; import datetime as dt<br \/>\n&gt;&gt;&gt; from decimal import Decimal<br \/>\n&gt;&gt;&gt;<br \/>\n&gt;&gt;&gt; while(1):<br \/>\n&gt;&gt;&gt; \u3000Model = input(&#8216;1.a\u2266n\u2266b\u306b\u5bfe\u3059\u308b\u30b3\u30e9\u30c3\u30c4\u30fb\u30b7\u30fc\u30af\u30a8\u30f3\u30b9\u306e\u30b9\u30c6\u30c3\u30d7\u6570\u306e\u6700\u5927\u5024\u3068n\u3092\u7b97\u51fa\\r\\n&#8217;<br \/>\n&gt;&gt;&gt; \u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000&#8217;2.a\u2266n\u2266b\u306b\u5bfe\u3059\u308b\u6a2a\u8ef8\u30b9\u30c6\u30c3\u30d7\u6570\u3001\u7e26\u8ef8\u983b\u5ea6\u306e\u68d2\u30b0\u30e9\u30d5\u63cf\u753b\\r\\n&#8217;<br \/>\n&gt;&gt;&gt;\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000 &#8216;1\u30012\u306e\u3069\u308c\u304b\u3092\u5165\u529b&gt;&gt;&gt; &#8216;)<br \/>\n&gt;&gt;&gt; if Model.isdecimal():<br \/>\n&gt;&gt;&gt; \u3000Model = int(Model)<br \/>\n&gt;&gt;&gt; \u3000if 1 &lt;= Model &lt;= 2:<br \/>\n&gt;&gt;&gt; \u3000\u3000break<br \/>\n&gt;&gt;&gt;<br \/>\n&gt;&gt;&gt;<br \/>\n&gt;&gt;&gt; # \u6a2a\u8ef8 \u30b9\u30c6\u30c3\u30d7\u6570s s=0,1,&#8230;,s_max-1<br \/>\n&gt;&gt;&gt; s_max = 1000<br \/>\n&gt;&gt;&gt; s = np.empty(s_max)<br \/>\n&gt;&gt;&gt;<br \/>\n&gt;&gt;&gt; S = np.empty(s_max)<br \/>\n&gt;&gt;&gt;<br \/>\n&gt;&gt;&gt; for i in range(s_max):<br \/>\n&gt;&gt;&gt;\u3000\u3000 s[i] = i<br \/>\n&gt;&gt;&gt;\u3000\u3000 S[i] = 0<br \/>\n&gt;&gt;&gt;<br \/>\n&gt;&gt;&gt; # \u30b9\u30c6\u30c3\u30d7\u6570\u304c\u6700\u5927\u3068\u306a\u308b\u3068\u304d\u3001n\u3068\u30b9\u30c6\u30c3\u30d7\u6570\u3092\u683c\u7d0d\u3059\u308b\u30ea\u30b9\u30c8<br \/>\n&gt;&gt;&gt; M = np.empty(2)<br \/>\n&gt;&gt;&gt; M[0] = 0<br \/>\n&gt;&gt;&gt; M[1] = 0<br \/>\n&gt;&gt;&gt;<br \/>\n&gt;&gt;&gt; def col(n):<br \/>\n&gt;&gt;&gt; \u3000\u3000N = n<br \/>\n&gt;&gt;&gt; \u3000\u3000c = 0<br \/>\n&gt;&gt;&gt;\u3000\u3000 while True:<br \/>\n&gt;&gt;&gt;\u3000\u3000\u3000\u3000 if n == 1:<br \/>\n&gt;&gt;&gt;\u3000\u3000\u3000\u3000\u3000\u3000 break<br \/>\n&gt;&gt;&gt;\u3000\u3000\u3000\u3000 if n % 2 == 0:<br \/>\n&gt;&gt;&gt;\u3000\u3000\u3000\u3000\u3000\u3000 n = Decimal(n)\/Decimal(&#8220;2&#8221;)<br \/>\n&gt;&gt;&gt;\u3000\u3000\u3000\u3000\u3000\u3000 c = c + 1<br \/>\n&gt;&gt;&gt;\u3000\u3000\u3000\u3000 else:<br \/>\n&gt;&gt;&gt;\u3000\u3000\u3000\u3000\u3000\u3000n = Decimal(&#8220;3&#8221;)*Decimal(n)+Decimal(&#8220;1&#8221;)<br \/>\n&gt;&gt;&gt;\u3000\u3000\u3000\u3000\u3000\u3000c = c + 1<br \/>\n&gt;&gt;&gt;\u3000\u3000\u3000if c &lt; s_max :<br \/>\n&gt;&gt;&gt;\u3000\u3000\u3000\u3000\u3000S[c] = S[c] + 1<br \/>\n&gt;&gt;&gt;\u3000\u3000\u3000if c &gt; M[1] :<br \/>\n&gt;&gt;&gt;\u3000\u3000\u3000\u3000\u3000M[0] = N<br \/>\n&gt;&gt;&gt;\u3000\u3000\u3000\u3000\u3000M[1] = c<br \/>\n&gt;&gt;&gt;<br \/>\n&gt;&gt;&gt; if Model == 1:<br \/>\n&gt;&gt;&gt; \u3000\u3000a = eval(input(&#8216;n\u306e\u59cb\u307e\u308a\u306f \u6570\u5f0fOK &#8216;))<br \/>\n&gt;&gt;&gt; \u3000\u3000b = eval(input(&#8216;n\u306e\u7d42\u308f\u308a\u306f \u6570\u5f0fOK &#8216;))<br \/>\n&gt;&gt;&gt;<br \/>\n&gt;&gt;&gt; \u3000\u3000time = dt.datetime<br \/>\n&gt;&gt;&gt; \u3000\u3000start = time.now() # \u6642\u9593\u8a08\u6e2c\u958b\u59cb<br \/>\n&gt;&gt;&gt; \u3000\u3000for i in range(a, b + 1):<br \/>\n&gt;&gt;&gt; \u3000\u3000\u3000\u3000col(i)<br \/>\n&gt;&gt;&gt; \u3000\u3000print(&#8216;n=&#8217;,int(M[0]),&#8217;max(Step)=&#8217;,int(M[1]))<br \/>\n&gt;&gt;&gt; \u3000\u3000stop = time.now() # \u6642\u9593\u8a08\u6e2c\u7d42\u4e86<br \/>\n&gt;&gt;&gt; \u3000\u3000t = stop &#8211; start<br \/>\n&gt;&gt;&gt; \u3000\u3000print(&#8216;\u8a08\u7b97\u6642\u9593&#8217;,t)<br \/>\n&gt;&gt;&gt;<br \/>\n&gt;&gt;&gt; elif Model == 2:<br \/>\n&gt;&gt;&gt; \u3000\u3000a = eval(input(&#8216;n\u306e\u59cb\u307e\u308a\u306f \u6570\u5f0fOK &#8216;))<br \/>\n&gt;&gt;&gt; \u3000\u3000b = eval(input(&#8216;n\u306e\u7d42\u308f\u308a\u306f \u6570\u5f0fOK &#8216;))<br \/>\n&gt;&gt;&gt;<br \/>\n&gt;&gt;&gt; \u3000\u3000#start = time.time() # \u6642\u9593\u8a08\u6e2c\u958b\u59cb<br \/>\n&gt;&gt;&gt;<br \/>\n&gt;&gt;&gt; \u3000\u3000#print(&#8216;n&#8217;+&#8217;\\t&#8217;+&#8217;Step&#8217;)<br \/>\n&gt;&gt;&gt; \u3000\u3000for i in range(a, b + 1):<br \/>\n&gt;&gt;&gt; \u3000\u3000\u3000\u3000col(i)<br \/>\n&gt;&gt;&gt; \u3000\u3000print(&#8216;n=&#8217;,int(M[0]),&#8217;max(Step)=&#8217;,int(M[1]))<br \/>\n&gt;&gt;&gt;<br \/>\n&gt;&gt;&gt; \u3000\u3000#t = time.time() &#8211; start # \u6642\u9593\u8a08\u6e2c\u7d42\u4e86<br \/>\n&gt;&gt;&gt; \u3000\u3000#print(&#8216;\u8a08\u7b97\u6642\u9593&#8217;,t,&#8217;\u79d2&#8217;)<br \/>\n&gt;&gt;&gt; \u3000\u3000plt.bar(s, S, color = &#8220;blue&#8221;)<br \/>\n&gt;&gt;&gt; \u3000\u3000plt.title(&#8216;\u30b3\u30e9\u30c3\u30c4\u4e88\u60f3\u306e\u691c\u8a3c\u3000\u30b3\u30e9\u30c3\u30c4\u30fb\u30b7\u30fc\u30af\u30a8\u30f3\u30b9 \u30b9\u30c6\u30c3\u30d7\u6570\u306e\u5206\u5e03\uff08{}\u2266n\u2266{}\uff09&#8217;.format(a,b))<br \/>\n&gt;&gt;&gt; \u3000\u3000plt.xlabel(&#8216;Step\u6570&#8217;)<br \/>\n&gt;&gt;&gt; \u3000\u3000plt.ylabel(&#8216;\u983b\u5ea6&#8217;)<br \/>\n&gt;&gt;&gt; \u3000\u3000plt.xticks(np.arange(0,s_max+0.1,50))<br \/>\n&gt;&gt;&gt; \u3000\u3000plt.grid(True)<br \/>\n&gt;&gt;&gt; \u3000\u3000plt.show()<\/p>\n<p><a href=\"http:\/\/ssfactory.sakura.ne.jp\/sakuraisusumu\/python\/colg.py\" target=\"_blank\" rel=\"noopener\">\u203b\u30d7\u30ed\u30b0\u30e9\u30e0\u30d5\u30a1\u30a4\u30eb\u306f\u3053\u3061\u3089\u304b\u3089\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\uff08\u30ea\u30f3\u30af\u5148\u306e\u30d5\u30a1\u30a4\u30eb\u3092\u5225\u540d\u3067\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\uff09\u3067\u304d\u307e\u3059\u3002<\/a><\/p>\n<h3><span class=\"ez-toc-section\" id=\"%E6%99%82%E5%88%86%E7%A7%92%E8%A1%A8%E7%A4%BA%E3%82%92%E8%A1%8C%E3%81%86datetime%E3%83%A2%E3%82%B8%E3%83%A5%E3%83%BC%E3%83%AB\"><\/span>\u6642\u5206\u79d2\u8868\u793a\u3092\u884c\u3046datetime\u30e2\u30b8\u30e5\u30fc\u30eb<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>\u524d\u56de\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u300ccol.gy\u300d\u3067\u306ftime\u30e2\u30b8\u30e5\u30fc\u30eb\u3092\u7528\u3044\u3066\u79d2\u306e\u8868\u793a\u3092\u884c\u3044\u307e\u3057\u305f\u3002<\/p>\n<p>\u4eca\u56de\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u300ccolg.gy\u300d\u3067\u306fdatetime\u30e2\u30b8\u30e5\u30fc\u30eb\u3092\u7528\u3044\u308b\u3053\u3068\u3067\u6642\u5206\u79d2\u306e\u8868\u793a\u3092\u884c\u3046\u3088\u3046\u306b\u3057\u307e\u3057\u305f\u3002<\/p>\n<h3><span class=\"ez-toc-section\" id=\"%E8%A8%88%E7%AE%97%E8%AA%A4%E5%B7%AE%E3%82%92%E9%98%B2%E3%81%90decimal%E3%83%A2%E3%82%B8%E3%83%A5%E3%83%BC%E3%83%AB\"><\/span>\u8a08\u7b97\u8aa4\u5dee\u3092\u9632\u3050decimal\u30e2\u30b8\u30e5\u30fc\u30eb<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>python\u3092\u30ce\u30fc\u30de\u30eb\u3067\u4f7f\u7528\u3059\u308b\u3068\u8a08\u7b97\u8aa4\u5dee\u304c\u751f\u3058\u307e\u3059\u3002\u3042\u308b\u610f\u5473python\u306e\u5bbf\u547d\u7684\u6b20\u70b9\u3067\u3059\u3002<\/p>\n<p>\u4eca\u56de\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u300ccolg.gy\u300d\u3067\u306f\u5927\u304d\u306a\u6570\u3092\u6271\u3046\u306e\u3067\u3001\u8a08\u7b97\u8aa4\u5dee\u304c\u554f\u984c\u306b\u306a\u3063\u3066\u304d\u307e\u3059\u3002<\/p>\n<p>\u305d\u3053\u3067\u3001\u4efb\u610f\u7cbe\u5ea6\u306e\u6570\u5024\u8a08\u7b97\u3092\u884c\u3046decimal\u30e2\u30b8\u30e5\u30fc\u30eb\u306e\u51fa\u756a\u3067\u3059\u3002<br \/>\n&gt;&gt;&gt; from decimal import Decimal<br \/>\n\u3068\u3057\u3066\u30a4\u30f3\u30dd\u30fc\u30c8\u3057\u307e\u3059\u3002<\/p>\n<p>\u30d7\u30ed\u30b0\u30e9\u30e0\u300ccol.gy\u300d\u306en = n\/2\u3068n = 3*n + 1\u306e\u30b3\u30fc\u30c9\u3092<br \/>\nn = n\/2\u3000\u2192\u3000n = Decimal(n)\/Decimal(&#8220;2&#8221;)<br \/>\nn = 3*n + 1\u3000\u2192\u3000n = Decimal(&#8220;3&#8221;)*Decimal(n)+Decimal(&#8220;1&#8221;)<br \/>\n\u306e\u3088\u3046\u306b\u3059\u308c\u3070\u6b63\u78ba\u306b\uff08\u30c7\u30d5\u30a9\u30eb\u30c8\u306f28\u6841\u306e\u7cbe\u5ea6\uff09\u8a08\u7b97\u3057\u3066\u304f\u308c\u307e\u3059\u3002<\/p>\n<h2><span class=\"ez-toc-section\" id=\"%E3%83%97%E3%83%AD%E3%82%B0%E3%83%A9%E3%83%A0%E3%80%8Ccolggy%E3%80%8D%E3%81%AE%E5%AE%9F%E8%A1%8C%E7%B5%90%E6%9E%9C\"><\/span>\u30d7\u30ed\u30b0\u30e9\u30e0\u300ccolg.gy\u300d\u306e\u5b9f\u884c\u7d50\u679c<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>$ python colg.py<br \/>\n1.a\u2266n\u2266b\u306b\u5bfe\u3059\u308b\u30b3\u30e9\u30c3\u30c4\u30fb\u30b7\u30fc\u30af\u30a8\u30f3\u30b9\u306e\u30b9\u30c6\u30c3\u30d7\u6570\u306e\u6700\u5927\u5024\u3068n\u3092\u7b97\u51fa<br \/>\n2.a\u2266n\u2266b\u306b\u5bfe\u3059\u308b\u6a2a\u8ef8\u30b9\u30c6\u30c3\u30d7\u6570\u3001\u7e26\u8ef8\u983b\u5ea6\u306e\u68d2\u30b0\u30e9\u30d5\u63cf\u753b<br \/>\n1\u30012\u306e\u3069\u308c\u304b\u3092\u5165\u529b&gt;&gt;&gt; 1<br \/>\nn\u306e\u59cb\u307e\u308a\u306f \u6570\u5f0fOK 1<br \/>\nn\u306e\u7d42\u308f\u308a\u306f \u6570\u5f0fOK 10**7<br \/>\nn= 8400511 max(Step)= 685<br \/>\n\u8a08\u7b97\u6642\u9593 0:21:02.099879<\/p>\n<p>$ python colg.py<br \/>\n1.a\u2266n\u2266b\u306b\u5bfe\u3059\u308b\u30b3\u30e9\u30c3\u30c4\u30fb\u30b7\u30fc\u30af\u30a8\u30f3\u30b9\u306e\u30b9\u30c6\u30c3\u30d7\u6570\u306e\u6700\u5927\u5024\u3068n\u3092\u7b97\u51fa<br \/>\n2.a\u2266n\u2266b\u306b\u5bfe\u3059\u308b\u6a2a\u8ef8\u30b9\u30c6\u30c3\u30d7\u6570\u3001\u7e26\u8ef8\u983b\u5ea6\u306e\u68d2\u30b0\u30e9\u30d5\u63cf\u753b<br \/>\n1\u30012\u306e\u3069\u308c\u304b\u3092\u5165\u529b&gt;&gt;&gt; 1<br \/>\nn\u306e\u59cb\u307e\u308a\u306f \u6570\u5f0fOK 1<br \/>\nn\u306e\u7d42\u308f\u308a\u306f \u6570\u5f0fOK 10**8<br \/>\nn= 63728127 max(Step)= 949<br \/>\n\u8a08\u7b97\u6642\u9593 4:07:28.299884<\/p>\n<p>1\u304b\u308910\u306e7\u4e57\u307e\u3067\u306en\u306e\u5834\u5408\u3001\u30b9\u30c6\u30c3\u30d7\u6570\u306e\u6700\u5927\u5024\u306f685\u3001\u8a08\u7b97\u6642\u9593\u306f21\u5206\u30011\u304b\u308910\u306e8\u4e57\u307e\u3067\u306en\u306e\u5834\u5408\u3001\u30b9\u30c6\u30c3\u30d7\u6570\u306e\u6700\u5927\u5024\u306f949\u3001\u8a08\u7b97\u6642\u9593\u306f4\u6642\u95937\u5206\u3067\u3057\u305f\u3002<\/p>\n<p>\u79c1\u306fpython\u3068NAS\u5c02\u7528\u30de\u30b7\u30f3\u306bubuntu\u3001Core i3\u30de\u30b7\u30f3\u3092\u4f7f\u3063\u3066\u3044\u307e\u3059\u3002\u5148\u65e5\u3001\u3055\u3089\u306b\u8a18\u9332\u66f4\u65b0\u3092\u72d9\u3063\u30661\u304b\u308910\u306e13\u4e57\u307e\u3067\u5b9f\u884c\u3055\u305b\u307e\u3057\u305f\u30021\u9031\u9593\u9023\u7d9a\u8a08\u7b97\u3092\u7d9a\u3051\u3066\u3082\u7d42\u4e86\u3057\u307e\u305b\u3093\u3067\u3057\u305f\u3002<\/p>\n<p>\u78ba\u304b\u306b\u300110\u306e8\u4e57\u306e\u5834\u5408\u306e10\u306e5\u4e57\u500d\uff0810\u4e07\u500d\uff09\u3060\u3068\u3059\u308b\u30684\u6642\u9593\u306e10\u4e07\u500d\u306740\u4e07\u6642\u9593\u3059\u306a\u308f\u306145\u5e74\u304b\u304b\u308b\u8a08\u7b97\u306b\u306a\u308a\u307e\u3059\u3002\u5358\u7d14\u8a08\u7b97\uff08\u30a2\u30eb\u30b4\u30ea\u30ba\u30e0\uff09\u306e\u9650\u754c\u3067\u3059\u3002<\/p>\n<p>\u8a18\u9332\u3092\u72d9\u3046\u306b\u306f\u3001\u30cf\u30fc\u30c9\u3068\u7406\u8ad6\u6b66\u88c5\u306e\u4e21\u9762\u3092\u5145\u5b9f\u3055\u305b\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u5186\u5468\u7387\u3084\u7d20\u6570\u306e\u8a08\u7b97\u3068\u540c\u3058\u3067\u3059\u3002<a href=\"http:\/\/www.ericr.nl\/wondrous\/delrecs.html\" target=\"_blank\" rel=\"noopener\">\u3053\u3053\u306b<\/a>\u30b3\u30e9\u30c3\u30c4\u30fb\u30b7\u30fc\u30af\u30a8\u30f3\u30b9\u306e\u30b9\u30c6\u30c3\u30d7\u6570\u306e\u8a18\u9332\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>n\u304c597\u4eac7996\u51463043\u51044350\u4e071855\uff0819\u6841\uff09\u306e\u3068\u304d2389\u30b9\u30c6\u30c3\u30d7\u304c\u6700\u9ad8\u8a18\u9332\u3067\u3059\u3002<\/p>\n<p>\u3053\u306e\u3088\u3046\u306b\u30b3\u30e9\u30c3\u30c4\u30fb\u30b7\u30fc\u30af\u30a8\u30f3\u30b9\u306e\u30b9\u30c6\u30c3\u30d7\u6570\u306f\u9ad8\u3005\u6570\u5343\u3067\u3059\u3002\u305d\u3053\u3067\u3001a\u2266n\u2266b\u306b\u5bfe\u3059\u308b\u30b9\u30c6\u30c3\u30d7\u6570\u306e\u983b\u5ea6\u3092\u8abf\u3079\u308b\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u30b3\u30fc\u30c7\u30a3\u30f3\u30b0\u3057\u3066\u307f\u307e\u3059\u3002<\/p>\n<p>\u30d7\u30ed\u30b0\u30e9\u30e0\u300ccolg.gy\u300d\u306e2\u3092\u9078\u3076\u3068\u3001a\u2266n\u2266b\u306b\u5bfe\u3059\u308bn\u306e\u30b9\u30c6\u30c3\u30d7\u6570\u3092\u8a08\u7b97\u3059\u308b\u3053\u3068\u3067\u30b9\u30c6\u30c3\u30d7\u6570\u6bce\u306e\u983b\u5ea6\u3092\u96c6\u8a08\u3057\u307e\u3059\u3002<\/p>\n<p>\u6b21\u304c\u305d\u306e\u5b9f\u884c\u7d50\u679c\u3067\u3059\u3002<\/p>\n<p>$ python colg.py<br \/>\n1.a\u2266n\u2266b\u306b\u5bfe\u3059\u308b\u30b3\u30e9\u30c3\u30c4\u30fb\u30b7\u30fc\u30af\u30a8\u30f3\u30b9\u306e\u30b9\u30c6\u30c3\u30d7\u6570\u306e\u6700\u5927\u5024\u3068n\u3092\u7b97\u51fa<br \/>\n2.a\u2266n\u2266b\u306b\u5bfe\u3059\u308b\u6a2a\u8ef8\u30b9\u30c6\u30c3\u30d7\u6570\u3001\u7e26\u8ef8\u983b\u5ea6\u306e\u68d2\u30b0\u30e9\u30d5\u63cf\u753b<br \/>\n1\u30012\u306e\u3069\u308c\u304b\u3092\u5165\u529b&gt;&gt;&gt; 2<br \/>\nn\u306e\u59cb\u307e\u308a\u306f \u6570\u5f0fOK 1<br \/>\nn\u306e\u7d42\u308f\u308a\u306f \u6570\u5f0fOK 10**8<br \/>\nn= 63728127 max(Step)= 949<\/p>\n<p><img decoding=\"async\" class=\"aligncenter size-full wp-image-13944\" src=\"https:\/\/club.informatix.co.jp\/wp-content\/uploads\/2021\/05\/20210529-2.jpg\" alt=\"\" width=\"800\" height=\"505\" srcset=\"https:\/\/club.informatix.co.jp\/wp-content\/uploads\/2021\/05\/20210529-2.jpg 800w, https:\/\/club.informatix.co.jp\/wp-content\/uploads\/2021\/05\/20210529-2-300x189.jpg 300w, https:\/\/club.informatix.co.jp\/wp-content\/uploads\/2021\/05\/20210529-2-768x485.jpg 768w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><\/p>\n<p>1\u304b\u308910\u306e6\u4e57\u307e\u3067\u306en\u306b\u3064\u3044\u3066\u30b9\u30c6\u30c3\u30d7\u6570\u3092\u8abf\u3079\u308b\u3068\u3001200\u3042\u305f\u308a\u306b\u96c6\u4e2d\u3057\u3066\u3044\u308b\u3053\u3068\u304c\u5206\u304b\u308a\u307e\u3059\u3002<\/p>\n<p>2020\u5e74\u306b2\u306e68\u4e57\uff0821\u6841\uff09\u307e\u3067\u691c\u8a3c\u306f\u3055\u308c\u3066\u3044\u307e\u3059\u3002\u4e88\u60f3\u306f\u6b63\u3057\u3044\u3088\u3046\u306b\u601d\u308f\u308c\u307e\u3059\u3002\u4e88\u60f3\u304c\u6210\u308a\u7acb\u305f\u306a\u3044\u3068\u8003\u3048\u308b\u6570\u5b66\u8005\u306f\u3044\u306a\u306e\u3067\u306f\u306a\u3044\u3067\u3057\u3087\u3046\u304b\u3002<\/p>\n<p>\u3057\u304b\u3057\u8a3c\u660e\u3055\u308c\u3066\u3044\u306a\u3044\u4ee5\u4e0a\u3001\u3055\u3089\u306b\u305d\u306e\u5148\u306e\u5927\u304d\u306a\u6570\u306b\u304a\u3044\u3066\u53cd\u4f8b\u304c\u898b\u3064\u304b\u308b\u5834\u5408\u3082\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>\u30b3\u30e9\u30c3\u30c4\u30fb\u89d2\u8c37\u4e88\u60f3\u306e\u89e3\u6c7a\u8005\u306b\u8cde\u91d1500\u30c9\u30eb\u3092\u4e0e\u3048\u308b\u3068\u8a00\u3063\u305f\u306e\u304c\u3001\u6570\u5b66\u8005\u30dd\u30fc\u30eb\u30fb\u30a8\u30eb\u30c7\u30b7\u30e5\uff081913-1996\uff09\u3067\u3059\u3002\u5f7c\u306f\u4e88\u60f3\u306b\u3064\u3044\u3066\u300c\u6570\u5b66\u306f\u307e\u3060\u3053\u306e\u7a2e\u306e\u554f\u984c\u306b\u5bfe\u3059\u308b\u7528\u610f\u304c\u3067\u304d\u3066\u3044\u306a\u3044\u300d\u3068\u8a9e\u308a\u307e\u3057\u305f\u3002<\/p>\n<p>\u30b3\u30e9\u30c3\u30c4\u30fb\u89d2\u8c37\u4e88\u60f3\u306f\u5c0f\u5b66\u751f\u3067\u3082\u5206\u304b\u308b\u5185\u5bb9\u306b\u3082\u304b\u304b\u308f\u3089\u305a\u3001\u305d\u306e\u6b63\u4f53\u304c\u9b51\u9b45\u9b4d\u9b4e\uff08\u3061\u307f\u3082\u3046\u308a\u3087\u3046\uff09\u3067\u3042\u308b\u672a\u89e3\u6c7a\u96e3\u554f\u3067\u3042\u308b\u306e\u304c\u9762\u767d\u3044\u3068\u3053\u308d\u3067\u3059\u3002<\/p>\n<p>Python\u3092\u7528\u3044\u3066\u3001\u624b\u8a08\u7b97\u3067\u306f\u5473\u308f\u3046\u3053\u3068\u304c\u3067\u304d\u306a\u3044\u9762\u767d\u3055\u3092\u5473\u308f\u3063\u3066\u307f\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u30b3\u30e9\u30c3\u30c4\u4e88\u60f3 \u524d\u56de\u306f\u30b3\u30e9\u30c3\u30c4\u30fb\u89d2\u8c37\u4e88\u60f3\u3092\u7d39\u4ecb\u3057\u3001\u4e88\u60f3\u3092\u691c\u8a3c\u3059\u308b\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u30b3\u30fc\u30c7\u30a3\u30f3\u30b0\u3057\u3066\u307f\u307e\u3057\u305f\u3002 \u4efb\u610f\u306e\u81ea\u7136\u6570\u306b\u5bfe\u3057\u3001\u5076\u6570\u306a\u30892\u3067\u5272\u308a\u3001\u5947\u6570\u306a\u30893\u500d\u30571\u3092\u8db3\u3059\u3001\u3068\u30448\u3046\u30b7\u30f3\u30d7\u30eb\u306a\u30a2\u30eb\u30b4\u30ea\u30ba\u30e0\u306b\u3088\u3063 &#8230; <\/p>\n","protected":false},"author":4,"featured_media":13944,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,464,526],"tags":[65,787],"class_list":["post-13940","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-4","category-hito-star-mathmatics","category-526","tag-python","tag-787"],"jetpack_featured_media_url":"https:\/\/club.informatix.co.jp\/wp-content\/uploads\/2021\/05\/20210529-2.jpg","_links":{"self":[{"href":"https:\/\/club.informatix.co.jp\/index.php?rest_route=\/wp\/v2\/posts\/13940","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/club.informatix.co.jp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/club.informatix.co.jp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/club.informatix.co.jp\/index.php?rest_route=\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/club.informatix.co.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=13940"}],"version-history":[{"count":15,"href":"https:\/\/club.informatix.co.jp\/index.php?rest_route=\/wp\/v2\/posts\/13940\/revisions"}],"predecessor-version":[{"id":20735,"href":"https:\/\/club.informatix.co.jp\/index.php?rest_route=\/wp\/v2\/posts\/13940\/revisions\/20735"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/club.informatix.co.jp\/index.php?rest_route=\/wp\/v2\/media\/13944"}],"wp:attachment":[{"href":"https:\/\/club.informatix.co.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=13940"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/club.informatix.co.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=13940"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/club.informatix.co.jp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=13940"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}