<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>factors Archives - Huahua&#039;s Tech Road</title>
	<atom:link href="https://zxi.mytechroad.com/blog/tag/factors/feed/" rel="self" type="application/rss+xml" />
	<link>https://zxi.mytechroad.com/blog/tag/factors/</link>
	<description></description>
	<lastBuildDate>Sun, 28 Mar 2021 23:29:11 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.0.8</generator>

<image>
	<url>https://zxi.mytechroad.com/blog/wp-content/uploads/2017/09/cropped-photo-32x32.jpg</url>
	<title>factors Archives - Huahua&#039;s Tech Road</title>
	<link>https://zxi.mytechroad.com/blog/tag/factors/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>花花酱 LeetCode 1808. Maximize Number of Nice Divisors</title>
		<link>https://zxi.mytechroad.com/blog/math/leetcode-1808-maximize-number-of-nice-divisors/</link>
					<comments>https://zxi.mytechroad.com/blog/math/leetcode-1808-maximize-number-of-nice-divisors/#respond</comments>
		
		<dc:creator><![CDATA[zxi]]></dc:creator>
		<pubDate>Sun, 28 Mar 2021 05:49:16 +0000</pubDate>
				<category><![CDATA[Math]]></category>
		<category><![CDATA[factors]]></category>
		<category><![CDATA[hard]]></category>
		<category><![CDATA[math]]></category>
		<category><![CDATA[prime]]></category>
		<guid isPermaLink="false">https://zxi.mytechroad.com/blog/?p=8290</guid>

					<description><![CDATA[<p>You are given a positive integer&#160;primeFactors. You are asked to construct a positive integer&#160;n&#160;that satisfies the following conditions: The number of prime factors of&#160;n&#160;(not necessarily&#8230;</p>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/math/leetcode-1808-maximize-number-of-nice-divisors/">花花酱 LeetCode 1808. Maximize Number of Nice Divisors</a> appeared first on <a rel="nofollow" href="https://zxi.mytechroad.com/blog">Huahua&#039;s Tech Road</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>You are given a positive integer&nbsp;<code>primeFactors</code>. You are asked to construct a positive integer&nbsp;<code>n</code>&nbsp;that satisfies the following conditions:</p>



<ul><li>The number of prime factors of&nbsp;<code>n</code>&nbsp;(not necessarily distinct) is&nbsp;<strong>at most</strong>&nbsp;<code>primeFactors</code>.</li><li>The number of nice divisors of&nbsp;<code>n</code>&nbsp;is maximized. Note that a divisor of&nbsp;<code>n</code>&nbsp;is&nbsp;<strong>nice</strong>&nbsp;if it is divisible by every prime factor of&nbsp;<code>n</code>. For example, if&nbsp;<code>n = 12</code>, then its prime factors are&nbsp;<code>[2,2,3]</code>, then&nbsp;<code>6</code>&nbsp;and&nbsp;<code>12</code>&nbsp;are nice divisors, while&nbsp;<code>3</code>&nbsp;and&nbsp;<code>4</code>&nbsp;are not.</li></ul>



<p>Return&nbsp;<em>the number of nice divisors of</em>&nbsp;<code>n</code>. Since that number can be too large, return it&nbsp;<strong>modulo</strong>&nbsp;<code>10<sup>9</sup>&nbsp;+ 7</code>.</p>



<p>Note that a prime number is a natural number greater than&nbsp;<code>1</code>&nbsp;that is not a product of two smaller natural numbers. The prime factors of a number&nbsp;<code>n</code>&nbsp;is a list of prime numbers such that their product equals&nbsp;<code>n</code>.</p>



<p><strong>Example 1:</strong></p>



<pre class="wp-block-preformatted;crayon:false"><strong>Input:</strong> primeFactors = 5
<strong>Output:</strong> 6
<strong>Explanation:</strong> 200 is a valid value of n.
It has 5 prime factors: [2,2,2,5,5], and it has 6 nice divisors: [10,20,40,50,100,200].
There is not other value of n that has at most 5 prime factors and more nice divisors.
</pre>



<p><strong>Example 2:</strong></p>



<pre class="wp-block-preformatted;crayon:false"><strong>Input:</strong> primeFactors = 8
<strong>Output:</strong> 18
</pre>



<p><strong>Constraints:</strong></p>



<ul><li><code>1 &lt;= primeFactors &lt;= 10<sup>9</sup></code></li></ul>



<h2><strong>Solution: Math</strong></h2>



<p>Time complexity: O(logn)<br>Space complexity: O(1)</p>



<div class="responsive-tabs">
<h2 class="tabtitle">C++</h2>
<div class="tabcontent">

<pre class="crayon-plain-tag">// Author: Huahua
class Solution {
public:
  int maxNiceDivisors(int n) {
    constexpr int kMod = 1e9 + 7;
    auto powm = [](long base, int exp) {
      long ans = 1;
      while (exp) {
        if (exp &amp; 1) ans = (ans * base) % kMod;
        base = (base * base) % kMod;
        exp &gt;&gt;= 1;
      }
      return ans;
    };
    
    if (n &lt;= 3) return n;
    switch (n % 3) {
      case 0: return powm(3, n / 3);
      case 1: return (powm(3, n / 3 - 1) * 4) % kMod;
      case 2: return (powm(3, n / 3) * 2) % kMod;
    }
    return -1;
  }
};</pre>
</div></div>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/math/leetcode-1808-maximize-number-of-nice-divisors/">花花酱 LeetCode 1808. Maximize Number of Nice Divisors</a> appeared first on <a rel="nofollow" href="https://zxi.mytechroad.com/blog">Huahua&#039;s Tech Road</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://zxi.mytechroad.com/blog/math/leetcode-1808-maximize-number-of-nice-divisors/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
