Class Solution
java.lang.Object
g2101_2200.s2183_count_array_pairs_divisible_by_k.Solution
2183 - Count Array Pairs Divisible by K.<p>Hard</p>
<p>Given a <strong>0-indexed</strong> integer array <code>nums</code> of length <code>n</code> and an integer <code>k</code>, return <em>the <strong>number of pairs</strong></em> <code>(i, j)</code> <em>such that:</em></p>
<ul>
<li><code>0 <= i < j <= n - 1</code> <em>and</em></li>
<li><code>nums[i] * nums[j]</code> <em>is divisible by</em> <code>k</code>.</li>
</ul>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> nums = [1,2,3,4,5], k = 2</p>
<p><strong>Output:</strong> 7</p>
<p><strong>Explanation:</strong></p>
<p>The 7 pairs of indices whose corresponding products are divisible by 2 are</p>
<p>(0, 1), (0, 3), (1, 2), (1, 3), (1, 4), (2, 3), and (3, 4).</p>
<p>Their products are 2, 4, 6, 8, 10, 12, and 20 respectively.</p>
<p>Other pairs such as (0, 2) and (2, 4) have products 3 and 15 respectively, which are not divisible by 2.</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> nums = [1,2,3,4], k = 5</p>
<p><strong>Output:</strong> 0</p>
<p><strong>Explanation:</strong> There does not exist any pair of indices whose corresponding product is divisible by 5.</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= nums.length <= 10<sup>5</sup></code></li>
<li><code>1 <= nums[i], k <= 10<sup>5</sup></code></li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
countPairs
public long countPairs(int[] nums, int k)
-