{"id":195,"date":"2023-01-01T12:00:00","date_gmt":"2023-01-01T04:00:00","guid":{"rendered":"https:\/\/www.vcoco.top\/?p=195"},"modified":"2023-01-01T11:53:36","modified_gmt":"2023-01-01T03:53:36","slug":"leetcode-%e7%ac%ac-326-%e5%9c%ba%e5%91%a8%e8%b5%9b","status":"publish","type":"post","link":"https:\/\/www.vcoco.top\/index.php\/2023\/01\/01\/leetcode-%e7%ac%ac-326-%e5%9c%ba%e5%91%a8%e8%b5%9b\/","title":{"rendered":"Leetcode \u7b2c 326 \u573a\u5468\u8d5b"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">\u5143\u65e6\u5feb\u4e50\uff01\uff01\uff01<\/h2>\n\n\n\n<p>\u539f\u9898\u94fe\u63a5\uff1ahttps:\/\/leetcode.cn\/contest\/weekly-contest-326<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u7edf\u8ba1\u80fd\u6574\u9664\u6570\u5b57\u7684\u4f4d\u6570<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>class Solution {\npublic:\n    int countDigits(int num) {\n        int t=num, res=0;\n        while(num){\n            if(t%(num%10) == 0) res++;\n            num\/=10;\n        }\n        \n        return res;\n    }\n};<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u6570\u7ec4\u4e58\u79ef\u4e2d\u7684\u4e0d\u540c\u8d28\u56e0\u6570\u6570\u76ee<\/h3>\n\n\n\n<p>\u6ce8\u610f\u8fb9\u4e58\u8fb9\u7b5b\u8d28\u56e0\u5b50<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class Solution {\npublic:\n    int distinctPrimeFactors(vector&lt;int&gt;&amp; nums) {\n        unordered_map&lt;int, int&gt; mp;\n        \n        for(auto val: nums)\n        {\n            int n=val;\n            for(int i=2; i&lt;=n\/i; i++)\n                while(n%i==0) n\/=i, mp&#91;i]++;\n            if(n&gt;1) mp&#91;n]++;\n        }\n        \n        return mp.size();\n    }\n};<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u5c06\u5b57\u7b26\u4e32\u5206\u5272\u6210\u503c\u4e0d\u8d85\u8fc7 K \u7684\u5b50\u5b57\u7b26\u4e32<\/h3>\n\n\n\n<p>\u8d2a\u5fc3<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class Solution {\npublic:\n    int minimumPartition(string s, int k) {\n        int res=0, sum=0;\n        int n=s.size();\n        for(int i=0; i&lt;n; i++){\n            int x=s&#91;i]-'0';\n            if(x&gt;k) return -1;\n            if(x+1ll*sum*10 &lt;= k) sum=sum*10+x;\n            else res++, sum=x;\n        }\n        \n        if(sum) res++;\n        return res;\n    }\n};<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u8303\u56f4\u5185\u6700\u63a5\u8fd1\u7684\u4e24\u4e2a\u8d28\u6570<\/h3>\n\n\n\n<p>\u628a $[1, right]$ \u4e4b\u95f4\u7684\u8d28\u6570\u5168\u90e8\u7b5b\u51fa\u6765\uff0c\u7136\u540e\u5bf9\u6ee1\u8db3\u6761\u4ef6\u7684\u9010\u4e00\u6bd4\u8f83\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class Solution {\npublic:\n    int primes&#91;1000010], cnt;\n    bool st&#91;1000010];\n    void euler(int n)\n    {\n        for(int i=2;i&lt;=n;i++)\n        {\n            if(!st&#91;i]) primes&#91;cnt++]=i;\n            for(int j=0;j&lt;cnt&amp;&amp;primes&#91;j]*i&lt;=n;j++)\n            {\n                st&#91;i*primes&#91;j]]=true;\n                if(i%primes&#91;j]==0) break;\n            }\n        }\n    }\n    vector&lt;int&gt; closestPrimes(int left, int right) {\n        euler(right);\n        \n        int k=-1, minv=0x3f3f3f3f;\n        for(int i=0;i&lt;cnt;i++){\n            if(primes&#91;i]&gt;=left &amp;&amp; i-1&gt;=0 &amp;&amp; primes&#91;i-1]&gt;=left) {\n                if(primes&#91;i]-primes&#91;i-1]&lt;minv) {\n                    k=i, minv=primes&#91;i]-primes&#91;i-1];\n                }\n            }\n        }\n        if(minv==0x3f3f3f3f) return {-1, -1};\n\n        return {primes&#91;k-1], primes&#91;k]};\n    }\n};<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u5143\u65e6\u5feb\u4e50\uff01\uff01\uff01 \u539f\u9898\u94fe\u63a5\uff1ahttps:\/\/leetcode.cn\/contest\/weekly-contest [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":205,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[79,37,80,57],"class_list":["post-195","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-leetcode","tag-leetcode","tag-sieve-primes","tag-80","tag-57"],"_links":{"self":[{"href":"https:\/\/www.vcoco.top\/index.php\/wp-json\/wp\/v2\/posts\/195","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.vcoco.top\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.vcoco.top\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.vcoco.top\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.vcoco.top\/index.php\/wp-json\/wp\/v2\/comments?post=195"}],"version-history":[{"count":5,"href":"https:\/\/www.vcoco.top\/index.php\/wp-json\/wp\/v2\/posts\/195\/revisions"}],"predecessor-version":[{"id":202,"href":"https:\/\/www.vcoco.top\/index.php\/wp-json\/wp\/v2\/posts\/195\/revisions\/202"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.vcoco.top\/index.php\/wp-json\/wp\/v2\/media\/205"}],"wp:attachment":[{"href":"https:\/\/www.vcoco.top\/index.php\/wp-json\/wp\/v2\/media?parent=195"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.vcoco.top\/index.php\/wp-json\/wp\/v2\/categories?post=195"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.vcoco.top\/index.php\/wp-json\/wp\/v2\/tags?post=195"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}