{"id":12181,"date":"2020-12-24T09:46:41","date_gmt":"2020-12-24T09:46:41","guid":{"rendered":"https:\/\/club.informatix.co.jp\/?p=12181"},"modified":"2024-04-30T05:59:20","modified_gmt":"2024-04-30T05:59:20","slug":"python%e3%81%a7%e6%95%b0%e5%ad%a6%e3%82%92%e5%ad%a6%e3%81%bc%e3%81%86%ef%bc%81%e6%a1%9c%e4%ba%95%e9%80%b2%e3%81%aepython%ef%bc%8bmath%e6%95%99%e5%ae%a4%e3%80%80%e7%ac%ac%ef%bc%94%e5%9b%9e","status":"publish","type":"post","link":"https:\/\/club.informatix.co.jp\/?p=12181","title":{"rendered":"\u7d20\u6570\u5224\u5b9a\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u30b3\u30fc\u30c7\u30a3\u30f3\u30b0\uff5cPython\u3067\u6570\u5b66\u3092\u5b66\u307c\u3046\uff01 \u7b2c4\u56de"},"content":{"rendered":"<p>56547511\u306f<a href=\"https:\/\/club.informatix.co.jp\/?p=4737\" target=\"_blank\" rel=\"noopener\">\u7d20\u6570<\/a>\u3067\u3057\u3087\u3046\u304b\uff1f<\/p>\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 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-69e6cbe33670a\" 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-69e6cbe33670a\" 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=12181\/#%E5%89%8D%E5%9B%9E%E3%81%AE%E3%83%95%E3%82%A3%E3%83%9C%E3%83%8A%E3%83%83%E3%83%81%E6%95%B0%E8%A1%A8%E7%A4%BA%E3%83%97%E3%83%AD%E3%82%B0%E3%83%A9%E3%83%A0%E3%82%92%E6%94%B9%E8%89%AF\" >\u524d\u56de\u306e\u30d5\u30a3\u30dc\u30ca\u30c3\u30c1\u6570\u8868\u793a\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u6539\u826f<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/club.informatix.co.jp\/?p=12181\/#%E3%83%97%E3%83%AD%E3%82%B0%E3%83%A9%E3%83%A0%EF%BC%9Afib2ipynb\" >\u30d7\u30ed\u30b0\u30e9\u30e0\uff1afib2.ipynb<\/a><\/li><\/ul><\/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=12181\/#%E7%B4%A0%E6%95%B0%E5%88%A4%E5%AE%9A%E3%83%97%E3%83%AD%E3%82%B0%E3%83%A9%E3%83%A0\" >\u7d20\u6570\u5224\u5b9a\u30d7\u30ed\u30b0\u30e9\u30e0<\/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=12181\/#%E3%83%97%E3%83%AD%E3%82%B0%E3%83%A9%E3%83%A0%EF%BC%9Aprime1ipynb\" >\u30d7\u30ed\u30b0\u30e9\u30e0\uff1aprime1.ipynb<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n\n<h2><span class=\"ez-toc-section\" id=\"%E5%89%8D%E5%9B%9E%E3%81%AE%E3%83%95%E3%82%A3%E3%83%9C%E3%83%8A%E3%83%83%E3%83%81%E6%95%B0%E8%A1%A8%E7%A4%BA%E3%83%97%E3%83%AD%E3%82%B0%E3%83%A9%E3%83%A0%E3%82%92%E6%94%B9%E8%89%AF\"><\/span>\u524d\u56de\u306e\u30d5\u30a3\u30dc\u30ca\u30c3\u30c1\u6570\u8868\u793a\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u6539\u826f<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><a href=\"https:\/\/club.informatix.co.jp\/?p=11714\" target=\"_blank\" rel=\"noopener\">\u524d\u56de<\/a>\u306e\u30d5\u30a3\u30dc\u30ca\u30c3\u30c1\u6570\u8868\u793a\u30d7\u30ed\u30b0\u30e9\u30e0\u306f<a href=\"https:\/\/www.python.org\/\" target=\"_blank\" rel=\"noopener\">Python\u672c\u5bb6\u672c\u5143\u30a6\u30a7\u30d6\u30b5\u30a4\u30c8<\/a>\u306b\u7d39\u4ecb\u3055\u308c\u3066\u3044\u308b\u3082\u306e\u3067\u3057\u305f\u3002<\/p>\n<p><span class=\"photoline\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-11732\" src=\"https:\/\/club.informatix.co.jp\/wp-content\/uploads\/2020\/12\/20201201-11.jpg\" alt=\"\" width=\"1280\" height=\"740\" srcset=\"https:\/\/club.informatix.co.jp\/wp-content\/uploads\/2020\/12\/20201201-11.jpg 1280w, https:\/\/club.informatix.co.jp\/wp-content\/uploads\/2020\/12\/20201201-11-300x173.jpg 300w, https:\/\/club.informatix.co.jp\/wp-content\/uploads\/2020\/12\/20201201-11-1024x592.jpg 1024w, https:\/\/club.informatix.co.jp\/wp-content\/uploads\/2020\/12\/20201201-11-768x444.jpg 768w\" sizes=\"(max-width: 1280px) 100vw, 1280px\" \/><\/span><\/p>\n<p>\u95a2\u6570fib(n)\u306fn\u3088\u308a\u5c0f\u3055\u3044\u30d5\u30a3\u30dc\u30ca\u30c3\u30c1\u6570\u3092\u8868\u793a\u3057\u307e\u3059\u3002<\/p>\n<p>\u521d\u9805\u3001\u7b2c0\u9805\u3068\u7b2c1\u9805\u3092\u305d\u308c\u305e\u308c0\u30681\u3068\u3057\u3066\u30010+1=1\u3092\u7b2c2\u9805\u30011+1=2\u3092\u7b2c2\u9805\u30011+2=3\u3092\u7b2c4\u9805\u3068\u6570\u5217\u3092\u751f\u6210\u3059\u308b\u30a2\u30eb\u30b4\u30ea\u30ba\u30e0\u306f<\/p>\n<p style=\"text-align: center;\">\u7b2cn+2\u9805\uff1d\u7b2cn\u9805\uff0b\u7b2cn+1\u9805<\/p>\n<p>\u306e\u95a2\u4fc2\u5f0f\u3067\u8868\u3055\u308c\u307e\u3059\u3002\u3053\u308c\u304c\u6b21\u306e\u30b3\u30fc\u30c9\u3067\u3059\u3002<\/p>\n<p>a, b = 0, 1<br \/>\na, b = b, a+b<\/p>\n<p>\u305d\u3053\u3067\u6b21\u306b\u7b2cn\u9805\u307e\u3067\u8868\u793a\u3059\u308b\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u8003\u3048\u3066\u307f\u307e\u3059\u3002<\/p>\n<h3><span class=\"ez-toc-section\" id=\"%E3%83%97%E3%83%AD%E3%82%B0%E3%83%A9%E3%83%A0%EF%BC%9Afib2ipynb\"><\/span>\u30d7\u30ed\u30b0\u30e9\u30e0\uff1afib2.ipynb<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>&gt;&gt;&gt; def fib(n):<br \/>\n&gt;&gt;&gt;\u00a0 \u00a0 a, b = 0, 1<br \/>\n&gt;&gt;&gt;\u00a0 \u00a0 for t in range(0, n+1):<br \/>\n&gt;&gt;&gt;\u00a0 \u00a0 \u00a0 \u00a0 print(f&#8217;\u7b2c{t}\u9805<span style=\"font-family: Arial;\">\\<\/span>t {a}&#8217;)<br \/>\n&gt;&gt;&gt;\u00a0 \u00a0 \u00a0 \u00a0 a, b = b, a+b<br \/>\n&gt;&gt;&gt;\u00a0 \u00a0 print()<br \/>\n&gt;&gt;&gt; fib(100)<\/p>\n<p>Google Colaboratory\uff08\u30b0\u30fc\u30b0\u30eb\u30b3\u30e9\u30dc\u30e9\u30c8\u30ea\u30fc\uff09\u3092\u30b0\u30fc\u30b0\u30eb\u30a2\u30ab\u30a6\u30f3\u30c8\u3067\u8d77\u52d5\u3057\u307e\u3059\u3002\u30ce\u30fc\u30c8\u30d6\u30c3\u30af\u3092\u65b0\u898f\u4f5c\u6210\u3057\u3066\u3001\u4e0a\u306e\u30b3\u30fc\u30c9\u3092\u30b3\u30d4\u30fc\u3057\u307e\u3059\u3002<\/p>\n<p>\u30d5\u30a1\u30a4\u30eb\u30cd\u30fc\u30e0\u3092fib2.ipynb\u3068\u3057\u3066\u4fdd\u5b58\u3057\u307e\u3059\u3002\u3053\u306e\u30d5\u30a1\u30a4\u30eb\u306f\u30b0\u30fc\u30b0\u30eb\u30c9\u30e9\u30a4\u30d6\u306eMy Drive\u306b\u4fdd\u5b58\u3055\u308c\u307e\u3059\u3002<\/p>\n<p><span class=\"photoline\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-12188\" src=\"https:\/\/club.informatix.co.jp\/wp-content\/uploads\/2020\/12\/20201224-1.jpg\" alt=\"\" width=\"746\" height=\"572\" srcset=\"https:\/\/club.informatix.co.jp\/wp-content\/uploads\/2020\/12\/20201224-1.jpg 746w, https:\/\/club.informatix.co.jp\/wp-content\/uploads\/2020\/12\/20201224-1-300x230.jpg 300w\" sizes=\"(max-width: 746px) 100vw, 746px\" \/><\/span><\/p>\n<p><span class=\"photoline\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-12184\" src=\"https:\/\/club.informatix.co.jp\/wp-content\/uploads\/2020\/12\/20201224-2.jpg\" alt=\"\" width=\"800\" height=\"269\" srcset=\"https:\/\/club.informatix.co.jp\/wp-content\/uploads\/2020\/12\/20201224-2.jpg 800w, https:\/\/club.informatix.co.jp\/wp-content\/uploads\/2020\/12\/20201224-2-300x101.jpg 300w, https:\/\/club.informatix.co.jp\/wp-content\/uploads\/2020\/12\/20201224-2-768x258.jpg 768w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><\/span><\/p>\n<p>\u30b3\u30fc\u30c9\u30921\u884c\u76ee\u304b\u3089\u898b\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n<p>def fib(n):<\/p>\n<p>\u95a2\u6570fib(n)\u306e\u5b9a\u7fa9\u3067\u3059\u3002\u30b3\u30ed\u30f3:\u3092\u5fd8\u308c\u306a\u3044\u3088\u3046\u306b\u3002\u4ee5\u4e0b\u306e\u30b3\u30fc\u30c9\u306f\u884c\u982d\u30a4\u30f3\u30c7\u30f3\u30c8\u3092\u884c\u3044\u307e\u3059\u3002<\/p>\n<p style=\"padding-left: 40px;\">a, b = 0, 1<\/p>\n<p>\u521d\u9805\u306e\u4ee3\u5165\u3067\u3059\u3002\u7b2c0\u8b1b\u3001\u7b2c1\u9805\u3092\u305d\u308c\u305e\u308ca\u3001b\u3068\u3057\u30660\u30681\u3092\u4ee3\u5165\u3057\u307e\u3059\u3002<\/p>\n<p style=\"padding-left: 40px;\">for t in range(0, n+1):<\/p>\n<p style=\"padding-left: 80px;\">print(f&#8217;\u7b2c{t}\u9805<span style=\"font-family: Arial;\">\\<\/span>t {a}&#8217;)<\/p>\n<p style=\"padding-left: 80px;\">a, b = b, a+b<\/p>\n<p>range()\u95a2\u6570\u306f\u9023\u7d9a\u3057\u305f\u6574\u6570\u3092\u751f\u6210\u3057\u307e\u3059\u3002<\/p>\n<p>range(0, n+1)\u306b\u3088\u308a0\u304b\u3089n\u307e\u3067\u306e\u6574\u6570\u3092\u751f\u6210\u3057\u307e\u3059\u3002<\/p>\n<p>\u4e00\u756a\u30b7\u30f3\u30d7\u30eb\u306arange(n)\u306f0\u304b\u3089n-1\u307e\u3067\u306en\u500b\u306e\u6574\u6570\u3092\u751f\u6210\u3057\u307e\u3059\u3002range(a, b)\u306fa\u304b\u3089b-1\u307e\u3067\u306e\u6574\u6570\u3092\u751f\u6210\u3057\u307e\u3059\u3002<\/p>\n<p>\u3053\u3053\u3067\u306f\u7b2c0\u9805\u304b\u3089\u7b2cn\u9805\u307e\u3067\u306e\u30d5\u30a3\u30dc\u30ca\u30c3\u30c1\u6570\u3092\u8868\u793a\u3055\u305b\u308b\u305f\u3081\u306brange(0, n+1)\u3068\u3057\u307e\u3059\u3002\u3082\u3061\u308d\u3093\u3001range(n+1)\u3068\u3057\u3066\u3082\u540c\u3058\u3067\u3059\u3002<\/p>\n<p>\u751f\u6210\u3055\u308c\u305f\u5024\u3092\u5909\u6570t\u306b0,1,2,\u2026,n\u306e\u9806\u306b\u4ee3\u5165\u3057\u3066\u3044\u304f\u306e\u304cfor\u6587\u3067\u3059\u3002for\u6587\u3082\u6700\u5f8c\u306b\u30b3\u30ed\u30f3:\u304c\u5fc5\u8981\u3067\u3059\u3002<\/p>\n<p>\u4ee5\u4e0b\u306e\u30b3\u30fc\u30c9\u306f\u884c\u982d\u30a4\u30f3\u30c7\u30f3\u30c8\u3057\u307e\u3059\u3002<\/p>\n<p style=\"padding-left: 80px;\">print(f&#8217;\u7b2c{t}\u9805<span style=\"font-family: Arial;\">\\<\/span>t {a}&#8217;)<\/p>\n<p style=\"padding-left: 80px;\">a, b = b, a+b<\/p>\n<p>\u30a4\u30f3\u30c7\u30f3\u30c8\u3055\u308c\u305f\u3053\u306e2\u884c\u304c\u3001t\u304c0\u304b\u3089n\u307e\u3067\u306e\u9593\u7e70\u308a\u8fd4\u3057\u51e6\u7406\u3055\u308c\u307e\u3059\u3002<\/p>\n<p>print(f&#8217;\u7b2c{t}\u9805<span style=\"font-family: Arial;\">\\<\/span>t {a}&#8217;)<\/p>\n<p>Python3.6\u4ee5\u964d\u3067\u306f f\u6587\u5b57\u5217(f-string)\u3068\u3044\u3046\u8868\u793a\u65b9\u6cd5\u304c\u4f7f\u7528\u53ef\u80fd\u3067\u3059\u3002<\/p>\n<p>print\u6587\u3067\u306f\u3088\u304f\u4f7f\u3046\u4fbf\u5229\u306a\u30b3\u30fc\u30c9\u3067\u3059\u3002print(f&#8221;)\u3068\u3059\u308b\u3053\u3068\u3067&#8221;\u306e\u4e2d\u306b\u5909\u6570\u3092\u6e21\u3057\u3066\u3001\u305d\u306e\u4e2d\u8eab\u3092\u8868\u793a\u3055\u305b\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>\u3053\u3053\u3067\u306f\u7b2ct\u9805\u3092\u8868\u3059\u5909\u6570t\u306e\u6570\u5024\u3092\u7528\u3044\u3066\u7b2c5\u9805\u3068\u8868\u793a\u3055\u305b\u307e\u3059\u3002\u305d\u308c\u304c\u7b2c{t}\u9805\u3068\u3044\u3046\u4f7f\u3044\u65b9\u3067\u3059\u3002<\/p>\n<p><span style=\"font-family: Arial;\">\\<\/span>t\u306f\u6c34\u5e73\u30bf\u30d6\uff08tab\uff09\u3092\u8868\u3057\u307e\u3059\u3002\u5909\u6570a\u306f\u7b2ct\u9805\u3092\u8868\u3057\u307e\u3059\u3002\u305d\u3053\u3067{a}\u3068\u3057\u307e\u3059\u3002<\/p>\n<p>\u30bf\u30d6\u306e\u304a\u304b\u3052\u3067\u5909\u6570a\u306e\u5148\u982d\u304c\u63c3\u3044\u307e\u3059\u3002<\/p>\n<p><span class=\"photoline\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-12185\" src=\"https:\/\/club.informatix.co.jp\/wp-content\/uploads\/2020\/12\/20201224-3.jpg\" alt=\"\" width=\"746\" height=\"434\" srcset=\"https:\/\/club.informatix.co.jp\/wp-content\/uploads\/2020\/12\/20201224-3.jpg 746w, https:\/\/club.informatix.co.jp\/wp-content\/uploads\/2020\/12\/20201224-3-300x175.jpg 300w\" sizes=\"(max-width: 746px) 100vw, 746px\" \/><\/span><\/p>\n<p style=\"padding-left: 40px;\">a, b = b, a+b<\/p>\n<p>\u3053\u308c\u304c\u30d5\u30a3\u30dc\u30ca\u30c3\u30c1\u6570\u306e\u30e1\u30a4\u30f3\u30fb\u30a2\u30eb\u30b4\u30ea\u30ba\u30e0\u3067\u3059\u3002<\/p>\n<p style=\"text-align: center;\">\u7b2ct+2\u9805\uff1d\u7b2ct\u9805\uff0b\u7b2ct+1\u9805<\/p>\n<p>\u7b2ct\u9805a\u3001\u7b2ct+1\u9805b\u306b\u5bfe\u3057\u3066\u3001\u5909\u6570t\u304c1\u3064\u5927\u304d\u304f\u306a\u308b\u3068\u7b2ct+1\u9805\u3092b\u3001\u7b2ct+2\u9805\u3092a+b\u3001\u3059\u306a\u308f\u3061\u7b2ct\u9805\uff0b\u7b2ct+1\u9805\u3068\u3059\u308b\u3068\u3044\u3046\u3053\u3068\u3067\u3059\u3002<\/p>\n<p style=\"padding-left: 40px;\">print()<\/p>\n<p>\u3053\u308c\u3067\u95a2\u6570fib(n)\u306e\u5b9a\u7fa9\u3092\u7d42\u308f\u308a\u306b\u3057\u307e\u3059\u3002\u5b9f\u306f\u3053\u306e1\u884c\u306f\u306a\u304f\u3066\u3082\u540c\u3058\u3088\u3046\u306b\u52d5\u3044\u3066\u304f\u308c\u307e\u3059\u3002<\/p>\n<p>fib(100)<\/p>\n<p>\u7b2c100\u9805\u307e\u3067\u8868\u793a\u3057\u307e\u3059\u3002f(1000)\u3068\u3057\u3066\u3082\u3001\u3042\u3063\u3068\u3044\u3046\u9593\u306b\u7b2c1000\u9805\u307e\u3067\u8868\u793a\u3055\u308c\u307e\u3059\u3002<\/p>\n<h2><span class=\"ez-toc-section\" id=\"%E7%B4%A0%E6%95%B0%E5%88%A4%E5%AE%9A%E3%83%97%E3%83%AD%E3%82%B0%E3%83%A9%E3%83%A0\"><\/span>\u7d20\u6570\u5224\u5b9a\u30d7\u30ed\u30b0\u30e9\u30e0<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>\u3055\u3063\u305d\u304f\u6b21\u306e\u30b3\u30fc\u30c9\u3092\u30b3\u30d4\u30fc\u3057\u3066\u3001\u30d5\u30a1\u30a4\u30eb\u540d\u3092prime1.ipynb\u3068\u3057\u3066\u4fdd\u5b58\u3057\u307e\u3059\u3002<\/p>\n<h3><span class=\"ez-toc-section\" id=\"%E3%83%97%E3%83%AD%E3%82%B0%E3%83%A9%E3%83%A0%EF%BC%9Aprime1ipynb\"><\/span>\u30d7\u30ed\u30b0\u30e9\u30e0\uff1aprime1.ipynb<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>&gt;&gt;&gt; n = int(input(&#8216;\u7d20\u6570\u5224\u5b9a\u3057\u305f\u30443\u4ee5\u4e0a\u306e\u6574\u6570n\u3092\u5165\u308c\u3066\u306d\u3002n=&#8217;))<br \/>\n&gt;&gt;&gt; for k in range(2,n):<br \/>\n&gt;&gt;&gt;\u00a0 \u00a0if n % k == 0:<br \/>\n&gt;&gt;&gt;\u00a0 \u00a0 \u00a0 print(f'{n} \u306f {k} \u3092\u7d04\u6570\u306b\u3082\u3064\u306e\u3067\u5408\u6210\u6570\u3001\u7d20\u6570\u3067\u306f\u3042\u308a\u307e\u305b\u3093\uff01&#8217;)<br \/>\n&gt;&gt;&gt;\u00a0 \u00a0 \u00a0 break<br \/>\n&gt;&gt;&gt; else:<br \/>\n&gt;&gt;&gt;\u00a0 \u00a0print(f'{n} \u306f\u7d20\u6570\uff01&#8217;)<\/p>\n<p>\u5b9f\u884c\u3055\u305b\u308b\u3068\u3001n\u306e\u5024\u3092\u305f\u305a\u306d\u3089\u308c\u307e\u3059\u3002<\/p>\n<p>12\u3092\u4ee3\u5165\u3057\u3066\u307f\u308b\u3068\u300112\u306f\u7d20\u6570\u3067\u306f\u3042\u308a\u307e\u305b\u3093\u3001\u3068\u8fd4\u3063\u3066\u304d\u307e\u3059\u3002645267\u3092\u4ee3\u5165\u3057\u3066\u307f\u308b\u3068\u3001645267\u306f\u7d20\u6570\u3067\u3059\u3001\u3068\u8fd4\u3063\u3066\u304d\u307e\u3059\u3002<\/p>\n<p>\u3053\u306e\u30b3\u30fc\u30c9\u306f\u30d5\u30a3\u30dc\u30ca\u30c3\u30c1\u6570\u306e\u3082\u306e\u3068\u540c\u3058\u884c\u6570\u3067\u3059\u3002for\u6587\u3001range()\u95a2\u6570\u306e\u3068\u3053\u308d\u306f\u540c\u3058\u3067\u3059\u3002<\/p>\n<p><span class=\"photoline\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-12186\" src=\"https:\/\/club.informatix.co.jp\/wp-content\/uploads\/2020\/12\/20201224-4.jpg\" alt=\"\" width=\"746\" height=\"379\" srcset=\"https:\/\/club.informatix.co.jp\/wp-content\/uploads\/2020\/12\/20201224-4.jpg 746w, https:\/\/club.informatix.co.jp\/wp-content\/uploads\/2020\/12\/20201224-4-300x152.jpg 300w\" sizes=\"(max-width: 746px) 100vw, 746px\" \/><\/span><\/p>\n<p><span class=\"photoline\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-12187\" src=\"https:\/\/club.informatix.co.jp\/wp-content\/uploads\/2020\/12\/20201224-5.jpg\" alt=\"\" width=\"746\" height=\"387\" srcset=\"https:\/\/club.informatix.co.jp\/wp-content\/uploads\/2020\/12\/20201224-5.jpg 746w, https:\/\/club.informatix.co.jp\/wp-content\/uploads\/2020\/12\/20201224-5-300x156.jpg 300w\" sizes=\"(max-width: 746px) 100vw, 746px\" \/><\/span><\/p>\n<p style=\"padding-left: 40px;\">if n % k == 0:<\/p>\n<p style=\"padding-left: 80px;\">print(f'{n} \u306f {k} \u3092\u7d04\u6570\u306b\u3082\u3064\u306e\u3067\u5408\u6210\u6570\u3001\u7d20\u6570\u3067\u306f\u3042\u308a\u307e\u305b\u3093\uff01&#8217;)<\/p>\n<p style=\"padding-left: 80px;\">break<\/p>\n<p>n % k\u306fn\u3092k\u3067\u5272\u3063\u305f\u4f59\u308a\u3067\u3059\u3002\u3053\u308c\u304c0\u306b\u7b49\u3057\u3044\u306a\u3089\u3070\u3001\u6b21\u306e\u30a4\u30f3\u30c7\u30f3\u30c8\u3055\u308c\u305f2\u884c\u3092\u5b9f\u884c\u3057\u307e\u3059\u3002n\u3092k\u3067\u5272\u3063\u305f\u4f59\u308a\u304c0\u3068\u3044\u3046\u3053\u3068\u306fk\u306fn\u306e\u7d04\u6570\u3068\u3044\u3046\u3053\u3068\u3067\u3059\u3002<\/p>\n<p>2\u4ee5\u4e0a\u306ek\u304c\u7d04\u6570\u3067\u3042\u308b\u3068\u3001\u305d\u306e\u6642\u70b9\u3067n\u306f\u7d20\u6570\u3067\u306f\u306a\u3044\u3068\u5224\u5b9a\u3055\u308c\u307e\u3059\u3002\u6b21\u306ebreak\u306b\u3088\u3063\u3066\u30d7\u30ed\u30b0\u30e9\u30e0\u306f\u7d42\u4e86\u3057\u307e\u3059\u3002<\/p>\n<p>else:<\/p>\n<p style=\"padding-left: 40px;\">print(f'{n} \u306f\u7d20\u6570\uff01&#8217;)<\/p>\n<p>range(2,n)\u306b\u3088\u3063\u3066k\u306f2\u304b\u3089n-1\u307e\u3067\u751f\u6210\u3055\u308c\u307e\u3059\u3002\u305d\u306e\u3059\u3079\u3066\u306ek\u304cn\u306e\u7d04\u6570\u3067\u306a\u3044\u3068else:\u304c\u5b9f\u884c\u3055\u308c\u307e\u3059\u3002n\u306e\u7d04\u6570\u304c1\u3068n\u3060\u3051\u3068\u306a\u308b\u306e\u3067n\u306f\u7d20\u6570\u3068\u5224\u5b9a\u3055\u308c\u307e\u3059\u3002<\/p>\n<p>\u5358\u7d14\u306a\u30a2\u30eb\u30b4\u30ea\u30ba\u30e0\u3067\u3059\u304c\u3001CPU\u30d1\u30ef\u30fc\u304c\u5927\u304d\u3044PC\u306b\u3068\u3063\u3066\u5927\u304d\u306an\u306b\u5bfe\u3057\u3066\u3082\u5224\u5b9a\u304c\u53ef\u80fd\u3067\u3059\u3002<\/p>\n<p>56547511\u306e\u7d20\u6570\u5224\u5b9a\u306b\u3069\u308c\u307b\u3069\u306e\u6642\u9593\u304c\u304b\u304b\u308b\u304b\u3001\u8a66\u3057\u3066\u307f\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>56547511\u306f\u7d20\u6570\u3067\u3057\u3087\u3046\u304b\uff1f \u524d\u56de\u306e\u30d5\u30a3\u30dc\u30ca\u30c3\u30c1\u6570\u8868\u793a\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u6539\u826f \u524d\u56de\u306e\u30d5\u30a3\u30dc\u30ca\u30c3\u30c1\u6570\u8868\u793a\u30d7\u30ed\u30b0\u30e9\u30e0\u306fPython\u672c\u5bb6\u672c\u5143\u30a6\u30a7\u30d6\u30b5\u30a4\u30c8\u306b\u7d39\u4ecb\u3055\u308c\u3066\u3044\u308b\u3082\u306e\u3067\u3057\u305f\u3002 \u95a2\u6570fib(n)\u306fn\u3088\u308a &#8230; <\/p>\n","protected":false},"author":4,"featured_media":12186,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,464,526],"tags":[65,380],"class_list":["post-12181","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-4","category-hito-star-mathmatics","category-526","tag-python","tag-380"],"jetpack_featured_media_url":"https:\/\/club.informatix.co.jp\/wp-content\/uploads\/2020\/12\/20201224-4.jpg","_links":{"self":[{"href":"https:\/\/club.informatix.co.jp\/index.php?rest_route=\/wp\/v2\/posts\/12181","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=12181"}],"version-history":[{"count":27,"href":"https:\/\/club.informatix.co.jp\/index.php?rest_route=\/wp\/v2\/posts\/12181\/revisions"}],"predecessor-version":[{"id":16884,"href":"https:\/\/club.informatix.co.jp\/index.php?rest_route=\/wp\/v2\/posts\/12181\/revisions\/16884"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/club.informatix.co.jp\/index.php?rest_route=\/wp\/v2\/media\/12186"}],"wp:attachment":[{"href":"https:\/\/club.informatix.co.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=12181"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/club.informatix.co.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=12181"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/club.informatix.co.jp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=12181"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}