{"id":232,"date":"2014-06-29T09:12:17","date_gmt":"2014-06-29T09:12:17","guid":{"rendered":"http:\/\/ixyzero.com\/blog\/?p=232"},"modified":"2014-06-29T09:12:17","modified_gmt":"2014-06-29T09:12:17","slug":"%e8%bd%ac%e8%af%bb%e3%80%8a%e7%bc%96%e7%a8%8b%e4%b9%8b%e7%be%8e%e3%80%8b%e6%9c%89%e6%84%9f-1%e7%9a%84%e4%b8%aa%e6%95%b0%ef%bc%9a%e6%95%b0%e5%ad%97x%e7%9a%84%e4%b8%aa%e6%95%b0","status":"publish","type":"post","link":"https:\/\/ixyzero.com\/blog\/archives\/232.html","title":{"rendered":"[collect]\u8bfb\u300a\u7f16\u7a0b\u4e4b\u7f8e\u300b\u6709\u611f\uff1a1\u7684\u4e2a\u6570-\u6570\u5b57x\u7684\u4e2a\u6570"},"content":{"rendered":"<h6>\u539f\u6587\u5730\u5740\uff1a<\/h6>\n<p><a style=\"line-height: 1.5;\" href=\"http:\/\/blog.csdn.net\/hinyunsin\/article\/details\/6321406\" target=\"_blank\">http:\/\/blog.csdn.net\/hinyunsin\/article\/details\/6321406<\/a><\/p>\n<div style=\"color: #000000;\">\n<h5 style=\"color: #333333;\">\u9898\u76ee\u662f\u8fd9\u6837\u7684\uff1a<\/h5>\n<p style=\"color: #333333;\"><span style=\"color: #ff0000;\">\u7ed9\u5b9a\u4e00\u4e2a\u5341\u8fdb\u5236\u7684\u6b63\u6574\u6570N\uff0c\u5199\u4e0b\u4ece1\u5f00\u59cb\uff0c\u5230N\u7684\u6240\u6709\u6574\u6570\uff0c\u7136\u540e\u6570\u4e00\u4e0b\u5176\u4e2d\u51fa\u73b0\u7684\u6240\u6709&#8221;1&#8243;\u7684\u4e2a\u6570<\/span>\u3002<\/p>\n<h6 style=\"color: #333333;\">\u4f8b\u5982\uff1a<\/h6>\n<p style=\"color: #333333;\">N=2\uff0c\u5199\u4e0b1,2\u3002\u8fd9\u6837\u53ea\u51fa\u73b0\u4e861\u4e2a&#8221;1&#8243;\u3002<\/p>\n<p style=\"color: #333333;\">N=12\uff0c\u6211\u4eec\u4f1a\u5199\u4e0b1,2,3,4,5,6,7,8,9,10,11,12\u3002\u8fd9\u68371\u7684\u4e2a\u6570\u662f5.<\/p>\n<h6 style=\"color: #333333;\">\u95ee\u9898\u662f\uff1a<\/h6>\n<ol style=\"color: #333333;\">\n<ol>\n<li>\u5199\u51fa\u4e00\u4e2a\u51fd\u6570f(N)\uff0c\u8fd4\u56de1\u5230N\u4e4b\u95f4\u51fa\u73b0&#8221;1&#8243;\u7684\u4e2a\u6570\uff0c\u6bd4\u5982f(12)=5<\/li>\n<li>\u572832\u4e3a\u6574\u6570\u8303\u56f4\u5185\uff0c\u6ee1\u8db3\u6761\u4ef6&#8221;f(N)=N&#8221;\u7684\u6700\u5927\u7684N\u662f\u591a\u5c11\uff1f<\/li>\n<\/ol>\n<\/ol>\n<p style=\"color: #333333;\">\u4e66\u4e2d\u7684\u89e3\u6cd5\u4e8c\u662f\uff1a\u901a\u8fc7\u5206\u6790&#8221;\u5c0f\u4e8e\u7b49\u4e8eN\u7684\u6570\u5728\u6bcf\u4e00\u4f4d\u4e0a\u53ef\u80fd\u51fa\u73b01\u7684\u6b21\u6570&#8221;\u4e4b\u548c\u6765\u5f97\u5230\u8fd9\u4e2a\u7ed3\u679c\u3002<strong><span style=\"color: #ff0000;\">\u4e0b\u9762\u662f\u5206\u6790\u8fc7\u7a0b\/\u65b9\u6cd5<\/span><\/strong>\uff1a<\/p>\n<p style=\"color: #333333;\">\u7ed9\u5b9a\u4e00\u4e2a\u6570\u5b57N\uff0c\u5047\u5b9a\u4ece\u4f4e\u4f4d\uff08\u4e2a\u4f4d\uff09\u5230\u9ad8\u4f4d\uff08\u5341\u4f4d\uff0c\u767e\u4f4d\uff0c\u5343\u4f4d\u3002\u3002\u3002\uff09\uff0c\u4ed6\u7684\u7b2ci\u4f4d\u4e3aB\uff0ci\u4f4d\u7684\u9ad8\u4f4d\u90e8\u5206\u4e3aA\uff0ci\u4f4d\u7684\u5730\u4f4d\u90e8\u5206\u4e3aC\uff0c\u56e0\u6b64\uff0c\u6211\u4eec\u5f97\u5230\u8fd9\u6837\u7684\u8ba1\u7b97\u516c\u5f0f\uff1a<\/p>\n<p style=\"color: #333333;\">N=A*10<sup>i<\/sup>+B*10<sup>i-1<\/sup>+C\uff0c\u6211\u4eec\u7528N=(A)B(C)\u6765\u63cf\u8ff0\uff1a\u4f8b\u5982i=3\uff0c\u90a3\u4e4812345=12*10<sup>3<\/sup>+3*10<sup>2<\/sup>+45\uff0c12345=(12)3(45)\uff08A=12\uff0cB=3\uff0cC=45\uff09<\/p>\n<p style=\"color: #333333;\">\u5728i\u8fd9\u4e2a\u4f4d\u7f6e\uff0cB\u4e3a1\u7684\u6570\u503c\u6709\u54ea\u4e9b\uff1a<\/p>\n<p style=\"color: #333333;\"><strong>1\uff1a<\/strong>\u5047\u8bbeB&gt;1\uff0c\u4ece(0)1(*)~(A)1(*)\uff08*\u8868\u793aC\u4e2d\u6bcf\u4e00\u4f4d\u5747\u53ef\u4ee5\u662f\u4efb\u610f\u6570\u5b57\uff09\u8303\u56f4\u5185\u7684\u6570\u5b57\u90fd\u5c0f\u4e8e(A)B(C)\uff0c\u603b\u5171\u6709\uff1a(A+1)*10<sup>i<\/sup>\u4e2a<\/p>\n<p style=\"color: #333333;\">\u4f8b\u598212345\uff0c\u5176\u4e2d(0)1(00)~(12)1(99)\u5c31\u662f\u7b2c3\u4e3a\u4e3a1\u7684\u6240\u6709\u60c5\u51b5\uff0c\u5927\u5c0f\u65f613*10<sup>3<\/sup>\u4e2a<\/p>\n<p style=\"color: #333333;\"><strong>2\uff1a<\/strong>\u5047\u8bbeB=1\uff0c\u5219\u4ece(0)1(*)~(A-1)1(*)\u8303\u56f4\u5185\u548c(A)1(0~C)\u8303\u56f4\u5185\u7684\u6240\u6709\u6570\u5b57\u90fd&lt;=(A)B(C)\uff0c\u603b\u5171\u6709\uff1aA*10<sup>i<\/sup>+(C+1)\u4e2a<\/p>\n<p style=\"color: #333333;\"><strong>3\uff1a<\/strong>\u5047\u8bbeB=0\uff0c\u5219\u4ece(0)1(*)~(A-1)1(*)\u8303\u56f4\u5185\u7684\u6240\u6709\u6570\u5b57\u90fd\u5c0f\u4e8e(A)B(C)\uff0c\u603b\u5171\u6709\uff1aA*10<sup>i<\/sup>\u00a0\u4e2a<\/p>\n<p style=\"color: #333333;\">\u7a0d\u5fae\u601d\u8003\u4e00\u4e0b\uff0c\u4f1a\u53d1\u73b0\uff0c\u8fd9\u4e2a\u65b9\u5f0f\u4e0d\u53ea\u662f\u5bf9\u67e5\u627e1\u7684\u4e2a\u6570\u6709\u7528\uff0c\u5bf9\u4e8e1~9\u8fd99\u4e2a\u6570\u5b57\u7684\u4e2a\u6570\u5747\u6709\u6548\uff0c\u552f\u4e00\u4e0d\u540c\u7684\u662f\uff0c\u8fd9\u91cc\u7684B\u4e0d\u518d\u540c1\u6bd4\u8f83\u5927\u5c0f\uff0c\u800c\u662f\u8ddf\u8981\u7edf\u8ba1\u7684\u6570\u5b57\u6bd4\u8f83\u5927\u5c0f<\/p>\n<p style=\"color: #333333;\"><strong>\u56e0\u6b64\u6211\u4eec\u5f97\u5230\u8fd9\u6837\u901a\u7528\u7684\u89e3\u6cd5\uff1a<\/strong><\/p>\n<p style=\"color: #333333;\">\u7ed9\u5b9a\u4e00\u4e2a\u5341\u8fdb\u5236\u7684\u6b63\u6574\u6570N\uff0c\u5199\u4e0b\u4ece1\u5f00\u59cb\uff0c\u5230N\u7684\u6240\u6709\u6574\u6570\uff0c\u7136\u540e\u6570\u4e00\u4e0b\u5176\u4e2d\u51fa\u73b0\u7684\u6240\u6709&#8221;x&#8221;\u7684\u4e2a\u6570\uff0c\u5176\u4e2d1&lt;=x&lt;=9\u3002\u5206\u6790\u65b9\u6cd5\uff1a<\/p>\n<p style=\"color: #333333;\">N=A*10<sup>i<\/sup>+B*10<sup>i-1<\/sup>+C\uff0c\u6211\u4eec\u7528N=(A)B(C)\u6765\u63cf\u8ff0\uff1a\u4f8b\u5982i=3\uff0c\u90a3\u4e4812345=12*10<sup>3<\/sup>+3*10<sup>2<\/sup>+45\uff0c12345=(12)3(45)\uff08A=12\uff0cB=3\uff0cC=45\uff09<\/p>\n<p style=\"color: #333333;\">\u5728i\u8fd9\u4e2a\u4f4d\u7f6e\uff0cB\u4e3a1\u7684\u6570\u503c\u6709\u54ea\u4e9b\uff1a<\/p>\n<p style=\"color: #333333; padding-left: 30px;\"><strong>1\uff1a<\/strong>\u5047\u8bbeB&gt;x\uff0c\u4ece(0)x(*)~(A)x(*)\uff08*\u8868\u793aC\u4e2d\u6bcf\u4e00\u4f4d\u5747\u53ef\u4ee5\u662f\u4efb\u610f\u6570\u5b57\uff09\u8303\u56f4\u5185\u7684\u6570\u5b57\u90fd\u5c0f\u4e8e(A)B(C)\uff0c\u603b\u5171\u6709\uff1a(A+1)*10<sup>i<\/sup>\u4e2a<\/p>\n<p style=\"color: #333333; padding-left: 30px;\">\u4f8b\u598212345\uff0c\u5176\u4e2d(0)1(00)~(12)1(99)\u5c31\u662f\u7b2c3\u4e3a\u4e3a1\u7684\u6240\u6709\u60c5\u51b5\uff0c\u5927\u5c0f\u65f613*10<sup>3<\/sup>\u4e2a<\/p>\n<p style=\"color: #333333; padding-left: 30px;\"><strong>2\uff1a<\/strong>\u5047\u8bbeB=x\uff0c\u5219\u4ece(0)x(*)~(A-1)x(*)\u8303\u56f4\u5185\u548c(A)x(0~C)\u8303\u56f4\u5185\u7684\u6240\u6709\u6570\u5b57\u90fd&lt;=(A)B(C)\uff0c\u603b\u5171\u6709\uff1aA*10<sup>i<\/sup>+(C+1)\u4e2a<\/p>\n<p style=\"color: #333333; padding-left: 30px;\"><strong>3\uff1a<\/strong>\u5047\u8bbeB&lt;x\uff0ci\u00a0\u4e2a<\/p>\n<p style=\"color: #333333;\">\u5bf9\u4e8e\u6574\u6570\u96f6\uff0c\u7a0d\u5fae\u6709\u70b9\u7279\u6b8a\uff1a<\/p>\n<ol style=\"color: #333333;\">\n<ol>\n<li>\u5047\u8bbeB&gt;0\uff0c\u5982\u679cA&gt;0\uff0c\u4e5f\u5c31\u662fi\u4e0d\u662fN\u7684\u6700\u9ad8\u4f4d\uff0c\u5219\u4ece(1)0(*)~(A)0(*)\uff08\u800c\u4e0d\u662f(0)x(*)~(A)x(*)\uff0c\u56e0\u4e3a\u8fd9\u91ccx=0\uff09\u8303\u56f4\u5185\u7684\u6570\u5b57\u90fd\u5c0f\u4e8e(A)B(C)\uff0c\u603b\u5171\u662f\u662fA*10<sup>i<\/sup>\u4e2a\uff0c\u5982\u679cA=0\uff0c\u8fd9\u6837\u7684\u6570\u5b57\u662f\u4e0d\u5b58\u5728\u7684<\/li>\n<li>\u5047\u8bbeB=0\uff0c\u5219A&gt;0\uff0c\u4ece(1)0(*)~(A)0(*)\u8303\u56f4\u5185\u548c(A)0(0~*)\u8303\u56f4\u5185\u7684\u6240\u6709\u6570\u5b57\u90fd&lt;=(A)B(C)\uff0c\u603b\u5171\u6709\uff1a(A-1)*10<sup>i<\/sup>+(C+1)\u4e2a<\/li>\n<li>\u6700\u540e\u8981+1\uff0c\u56e0\u4e3a0\u6ca1\u6709\u88ab\u8ba1\u7b97\u8fdb\u53bb\uff0c\u5bf9\u4e8e\u4efb\u610f\u6b63\u6574\u6570\uff0c0\u603b\u662f\u5c0f\u4e8e\u5b83\u7684\u3002<\/li>\n<\/ol>\n<\/ol>\n<h6 style=\"color: #333333;\">\u8d34\u4e0apython\u4ee3\u7801\u5982\u4e0b\uff1a<\/h6>\n<pre class=\"lang:default decode:true \">#!\/usr\/bin\/python\n#coding=utf-8\n#Filename: numCount.py\n'''\nCreate on 2011-04-12\n@author: boyce\n@contact: boyce.ywr@gmail.com\n@version 1.0\n'''\ndef sums(val, num):\n    iCount = 0\t#\u603b\u6570\u521d\u503c\u8bbe\u4e3a0\n    iFactor = 1\t#\u63d0\u524d\u8bbe\u7f6e\u6743\u503c\u4e3a1\uff0c\u5373\u4e2a\u4f4d\n    iLowerNum = 0\n    iCurrNum = 0\n    iHigherNum = 0\n\n    if num == 0:\n        while (val \/ iFactor) != 0:\n            iLowerNum = val - (val \/ iFactor) * iFactor\n            iCurrNum = (val \/ iFactor) % 10\n            iHigherNum = val \/ (iFactor * 10)\n            if iCurrNum == 0:\n                iCount += (iHigherNum - 1) * iFactor + iLowerNum + 1\n            elif iHigherNum &gt; 0:\n                iCount += iHigherNum * iFactor\n            iFactor *= 10\n        return iCount + 1\n\n    while (val \/ iFactor) != 0:\n        iLowerNum = val - (val \/ iFactor) * iFactor\n        iCurrNum = (val \/ iFactor) % 10\n        iHigherNum = val \/ (iFactor * 10)\n        if iCurrNum &lt; num:\n            iCount += iHigherNum * iFactor\n        elif iCurrNum == num:\n            iCount += iHigherNum * iFactor + iLowerNum + 1\n        else:\n            iCount += (iHigherNum + 1) * iFactor\n        iFactor *= 10\n    return iCount\n\nif __name__ == '__main__':\n    num = 33333\n    print '0: ', sums(num, 0)\n    print '1: ', sums(num, 1)\n    print '2: ', sums(num, 2)\n    print '3: ', sums(num, 3)\n    print '4: ', sums(num, 4)\n    print '5: ', sums(num, 5)\n    print '6: ', sums(num, 6)\n    print '7: ', sums(num, 7)\n    print '8: ', sums(num, 8)\n    print '9: ', sums(num, 9)<\/pre>\n<p>\u540e\u8bb0\uff1a\u6211\u81ea\u5df1\u540e\u6765\u4e5f\u7167\u7740\u8fd9\u4e2a\u601d\u8def\u5199\u4e86\u4e2aPHP\u7248\u7684\uff0c\u4f46\u662f\u548c\u8fd9\u4e2aPython\u7248\u7684\u6bd4\u8d77\u6765\u592a\u6413\u4e86\uff0c\u5c31\u6ca1\u6709\u653e\u4e0a\u6765\u2026\u2026<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u539f\u6587\u5730\u5740\uff1a http:\/\/blog.csdn.net\/hinyunsin\/article\/details\/63 [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[109,8],"class_list":["post-232","post","type-post","status-publish","format-standard","hentry","category-programing","tag-algorithm","tag-python"],"views":2796,"_links":{"self":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/232","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/comments?post=232"}],"version-history":[{"count":0,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/232\/revisions"}],"wp:attachment":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/media?parent=232"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/categories?post=232"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/tags?post=232"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}