{"id":913,"date":"2014-06-08T05:06:49","date_gmt":"2014-06-07T21:06:49","guid":{"rendered":"http:\/\/www.shuizilong.com\/house\/?p=913"},"modified":"2014-06-08T05:06:49","modified_gmt":"2014-06-07T21:06:49","slug":"tco-2b","status":"publish","type":"post","link":"https:\/\/www.shuizilong.com\/house\/archives\/tco-2b\/","title":{"rendered":"TCO 2B"},"content":{"rendered":"<h2>900. <\/h2>\n<h3>Brief description:<\/h3>\n<p>f(x) = x%m==0 \u672a\u5b9a\u4e49<br \/>\n      = x\/(x%m), otherwise<br \/>\n\u6c42\u5728\u533a\u95f4 [l, r] \u8303\u56f4\u5185\uff0c\u5bf9\u4efb\u610f\u7684 k>=1\uff0c f^k(x) \u90fd\u6709\u5b9a\u4e49\u7684 x \u7684\u6570\u76ee<br \/>\n&#8230;<\/p>\n<h3>Analysis:<\/h3>\n<p>\u6211\u4eec\u8bbe $$f(x)$$ \u3002\u3002\u4f7f\u5f97\u7b54\u6848\u4e3a $$f(r) &#8211; f(l-1)$$&#8230;<br \/>\n\u3002\u3002\u8003\u8651\u9012\u5f52\u89e3\u51b3\u3002<\/p>\n<p>\u8fd9\u6837\u53ea\u9700\u8981\u8003\u8651\u4e00\u6b21\u51fd\u6570\u7684\u4f5c\u7528\u3002\u3002<br \/>\n\u3002\u3002\u8bbe r \u4e3a\u6a21 m \u7684\u4f59\u6570\u3002\u3002<br \/>\n\u6211\u4eec\u5c1d\u8bd5\u5bf9 r \u8fdb\u884c\u5206\u7ec4\u3002\u3002<\/p>\n<p>\u4e0d\u59a8\u8003\u8651 m = 6\uff0c<\/p>\n<p>1 7 13 ..<br \/>\n2 8 14 &#8230;<br \/>\n3 9 ..<br \/>\n4 10 ..<br \/>\n5 11 ..<\/p>\n<p>1 <\/p>\n<p>Case 1\uff1a<\/p>\n<p>\u82e5 r = 1 \u663e\u7136\u90fd\u5408\u6cd5\u3002\u3002\u53ef\u4ee5\u76f4\u63a5\u8ba1\u7b97\u51fa\u6765\u3002\u3002\u3002<br \/>\n\u3002\u3002\u3002\u3002\u66f4\u8fdb\u4e00\u6b65\u3002\u6211\u4eec\u53d1\u73b0.\u3002\u3002\u5bf9\u4e8e\u6240\u6709 r \u22a5m \u4e92\u8d28\u7684\u60c5\u51b5\uff0c\u505a\u6cd5\u90fd\u662f\u7c7b\u4f3c\u7684\u3002\u3002\u3002<br \/>\n\u4f8b\u5982\u3002\u3002\u89c2\u5bdf\u4e0a\u9762 r = 5\uff1a5 11 17 23 29 35 \u3002\u3002\u3002<br \/>\n\u3002\u3002 \/m \u540e\u53d8\u6210\uff1a1 x x x x 7 x x x x 13 \u3002\u3002\u3002\u548c r = 1 \u7684\u60c5\u51b5\u662f\u4e00\u81f4\u7684\u3002\u3002<br \/>\n\u3002\u3002\u3002\u3002\u4e5f\u5c31\u662f\u3002\u3002\u5bf9\u7b54\u6848\u7684\u8d21\u732e\u4e3a\u3002\u3002ceil(nn, r)\u3002\u3002\uff08\u8fd9\u91cc\u7684 nn \u76f8\u5f53\u4e8e\u628a n \u538b\u7f29\u4e0b\u3002.\u3002\uff09<\/p>\n<p>\uff08Tips\uff1a\u6ce8\u610f nn \u8fd9\u91cc\u662f  #define nn ((n-r)\/m+1)<br \/>\n\u3002\u3002\u3002\u3002\u4f46\u662f\u5b9e\u9645\u3002\u3002\u6211\u4eec\u5927\u53ef\u4ee5\u7559\u4e2a\u6807\u8bb0\u3002\u3002<br \/>\n\u3002\u3002\u7136\u540e\u7ee7\u7eed\u5f80\u4e0b\u601d\u8003\u3002\u3002\u4e0d\u5fc5\u518d\u6b21\u5c31\u6df1\u7a76 nn \u7684\u5177\u4f53\u503c\u3002\u3002<br \/>\n\u3002\u3002\u3002\u56e0\u4e3a\u968f\u7740\u7a0b\u5e8f\u7ed3\u6784\u7684\u6e05\u6670\u3002\u3002\u3002\u8fd9\u4e9b\u503c\u53ef\u80fd\u7528\u4e0d\u5230\u6216\u8005\u4ee3\u66ff\u6216\u88ab\u88ab\u7ea6\u53bb\u3002\u3002\u3002\uff09<\/p>\n<p>Case 2\uff1a<br \/>\n\u3002\u3002\u82e5 r \\not \u22a5 m\u3002\u3002\u3002<br \/>\n\u3002\u3002\u6211\u4eec\u4ee5\u4e0a\u9762\u7684 r = 4 \u4e3a\u4f8b\u5427\u3002\u3002\u3002\u3002<\/p>\n<p>4 10 14 20 26 30 36 &#8230;<br \/>\n-><br \/>\n1  x    x   5   x   x   9 &#8230;.<\/p>\n<p>\u5b9e\u9645\u4e0a\u5c31\u662f\u628a n \u538b\u7f29\u4e00\u4e0b\u3002\u3002\u7136\u540e\u4fee\u6539\u4e00\u4e0b\u6b65\u957f\u3002\u3002\u3002<br \/>\n\u56e0\u4e3a\u6211\u4eec\u7684  f()  \u8fd8\u9700\u8981\u6dfb\u52a0\u4e00\u4e2a\u6b65\u957f d\u3002\u3002\u521d\u59cb\u4e3a 1\u3002\u3002\u800c\u4e0a\u9762\u4e92\u8d28\u7684\u60c5\u51b5\u76f8\u5f53\u4e8e\u4e00\u4e2a\u8fb9\u754c\u6761\u4ef6\u3002\u3002d = m\u3002<\/p>\n<p>\u3002\u3002\u8fd9\u6837\u5c31\u53ef\u4ee5\u4e86\u3002\u3002\u3002\u3002<\/p>\n<p>\u3002\u3002\u3002\u8fd9\u4e2a\u7b97\u6cd5\u8dd1\u7684\u5f88\u5feb\u3002\u3002\u3002\u4f46\u662f\u6211\u4e0d\u4f1a\u5bf9\u5176\u8fdb\u884c\u5206\u6790\u3002\u3002\u3002\u3002<br \/>\n\u3002\u3002\u3002\u8fd9\u4e2a\u9898\u6211\u7684\u505a\u6cd5\u548c\u5f53\u65f6 SRM 622 900 \u7684\u601d\u7ef4\u56de\u8def\u662f\u4e00\u6837\u7684\u3002\u3002\u53ef\u662f\u8fd9\u4e00\u6b21\u6211\u5374\u672a\u80fd\u4f5c\u51fa\u3002\u3002<br \/>\n\u3002\u3002\u3002\u3002\u4e3b\u8981\u662f\u5bf9\u4e2d\u95f4 gcd() \u4e00\u5e26\u7684\u6297\u6027\u592a\u4f4e\u4e86\u3002\u3002\u3002\u5bf9 pattern \u7684\u6d1e\u5bdf\u529b\u4e0d\u591f\u3002\u3002\u3002\u3002<br \/>\n\u3002\u3002\u3002\u81ea\u59cb\u81f3\u7ec8\u90fd\u6ca1\u6709\u628a \u3010\u6b65\u957f\u3011 \u8fd9\u5219\u5173\u952e\u4fe1\u606f\u5f52\u7eb3\u51fa\u6765\u3002\u3002\u800c\u662f\u5728\u5b50\u95ee\u9898\u4e2d\u4e0d\u505c\u7684\u5c1d\u8bd5\u53bb\u4fee\u6539\u6a21\u6570 m\u3002\u3002\u3002<br \/>\n\u3002\u3002\u751a\u81f3\u90fd\u4e00\u5ea6\u60f3\u5230\u6a21\u7ebf\u6027\u65b9\u7a0b\u548c\u83ab\u6bd4\u4e4c\u65af\u53cd\u6f14\u4e0a\u9762\u53bb\u4e86\u3002\u3002\u3002\u3002<\/p>\n<pre class=\"brush: cpp; light: false; title: ; toolbar: true; notranslate\" title=\"\">\r\ntemplate&lt;class T&gt; inline T ceil(T x, T y){return (x - 1) \/ y + 1;}\r\n\r\n#define nn ((n-r)\/r+1)\r\n#define g __gcd(m,r)\r\n\r\nint m; LL f(LL n, int d = 1){\r\n    if (n &lt;= 0) return 0; if (d == m) return ceil(n,(LL)m);\r\n    LL res = 0; int mm = min((LL)m, n+1);\r\n    for (int r=1;r&lt;mm;r+=d) res += f(nn,m\/g);\r\n    return res;\r\n}\r\n\r\nclass AlwaysDefined {\r\npublic:\r\n\tlong long countIntegers(long long L, long long R, int W) {\r\n        m = W; return f(R) - f(L-1);\r\n\t}\r\n};\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>900. Brief description: f(x) = x%m==0 \u672a\u5b9a\u4e49 = x\/(x%m), otherwise \u6c42\u5728\u533a\u95f4 [l, r] \u8303\u56f4\u5185\uff0c\u5bf9\u4efb\u610f\u7684 k>=1\uff0c f^k(x) \u90fd\u6709\u5b9a\u4e49\u7684 x \u7684\u6570\u76ee &#8230; Analysis: \u6211\u4eec\u8bbe $$f(x)$$ \u3002\u3002\u4f7f\u5f97\u7b54\u6848\u4e3a $$f(r) &#8211; f(l-1)$$&#8230; \u3002\u3002\u8003\u8651\u9012\u5f52\u89e3\u51b3\u3002 \u8fd9\u6837\u53ea\u9700\u8981\u8003\u8651\u4e00\u6b21\u51fd\u6570\u7684\u4f5c\u7528\u3002\u3002 \u3002\u3002\u8bbe r \u4e3a\u6a21 m \u7684\u4f59\u6570\u3002\u3002 \u6211\u4eec\u5c1d\u8bd5\u5bf9 r \u8fdb\u884c\u5206\u7ec4\u3002\u3002 \u4e0d\u59a8\u8003\u8651 m = 6\uff0c 1 7 13 .. 2 8 14 &#8230; 3 9 .. 4 10 .. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[1],"tags":[],"class_list":["post-913","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p2tdP7-eJ","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/913","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/comments?post=913"}],"version-history":[{"count":0,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/913\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/media?parent=913"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/categories?post=913"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/tags?post=913"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}