We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 0ad002b commit 10d93e1Copy full SHA for 10d93e1
2183-count-array-pairs-divisible-by-k.js
@@ -0,0 +1,27 @@
1
+/**
2
+ * @param {number[]} nums
3
+ * @param {number} k
4
+ * @return {number}
5
+ */
6
+const coutPairs = function(nums, k) {
7
+ let res = 0;
8
+ let cnt = Array(1e5 + 1).fill(0);
9
+ const n = nums.length
10
+ for (let i = 0; i < n; ++i) {
11
+ if (nums[i] % k == 0) {
12
+ res += i;
13
+ ++cnt[0];
14
+ }
15
+ else {
16
+ let div = gcd(k, nums[i]);
17
+ for (let d = 0; d <= div; ++d) res += cnt[k / div * d];
18
+ ++cnt[div];
19
20
21
+ return res;
22
+};
23
+
24
+function gcd(a, b) {
25
+ if(b === 0) return a
26
+ return gcd(b, a % b)
27
+}
0 commit comments