Class Solution
java.lang.Object
g1801_1900.s1819_number_of_different_subsequences_gcds.Solution
1819 - Number of Different Subsequences GCDs.<p>Hard</p>
<p>You are given an array <code>nums</code> that consists of positive integers.</p>
<p>The <strong>GCD</strong> of a sequence of numbers is defined as the greatest integer that divides <strong>all</strong> the numbers in the sequence evenly.</p>
<ul>
<li>For example, the GCD of the sequence <code>[4,6,16]</code> is <code>2</code>.</li>
</ul>
<p>A <strong>subsequence</strong> of an array is a sequence that can be formed by removing some elements (possibly none) of the array.</p>
<ul>
<li>For example, <code>[2,5,10]</code> is a subsequence of <code>[1,2,1, **2** ,4,1, **5** , **10** ]</code>.</li>
</ul>
<p>Return <em>the <strong>number</strong> of <strong>different</strong> GCDs among all <strong>non-empty</strong> subsequences of</em> <code>nums</code>.</p>
<p><strong>Example 1:</strong></p>
<p><img src="https://assets.leetcode.com/uploads/2021/03/17/image-1.png" alt="" /></p>
<p><strong>Input:</strong> nums = [6,10,3]</p>
<p><strong>Output:</strong> 5</p>
<p><strong>Explanation:</strong> The figure shows all the non-empty subsequences and their GCDs. The different GCDs are 6, 10, 3, 2, and 1.</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> nums = [5,15,40,5,6]</p>
<p><strong>Output:</strong> 7</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= nums.length <= 10<sup>5</sup></code></li>
<li><code>1 <= nums[i] <= 2 * 10<sup>5</sup></code></li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
countDifferentSubsequenceGCDs
public int countDifferentSubsequenceGCDs(int[] nums)
-