We need to count all pairs (i, j) such that nums1[i] is divisible by nums2[j] * k. Since the constraints are small, we can check every possible pair directly.
classSolution {
public:int numberOfPairs(vector<int>& nums1, vector<int>& nums2, int k) {
int ans =0;
for (int a : nums1) {
for (int b : nums2) {
if (a % (b * k) ==0) ans++;
}
}
return ans;
}
};
classSolution {
publicintnumberOfPairs(int[] nums1, int[] nums2, int k) {
int ans = 0;
for (int a : nums1) {
for (int b : nums2) {
if (a % (b * k) == 0) ans++;
}
}
return ans;
}
}
1
2
3
4
5
6
7
8
9
10
11
classSolution {
funnumberOfPairs(nums1: IntArray, nums2: IntArray, k: Int): Int {
var ans = 0for (a in nums1) {
for (b in nums2) {
if (a % (b * k) ==0) ans++ }
}
return ans
}
}
1
2
3
4
5
6
7
8
classSolution:
defnumberOfPairs(self, nums1: list[int], nums2: list[int], k: int) -> int:
ans =0for a in nums1:
for b in nums2:
if a % (b * k) ==0:
ans +=1return ans
1
2
3
4
5
6
7
8
9
10
11
12
13
impl Solution {
pubfnnumber_of_pairs(nums1: Vec<i32>, nums2: Vec<i32>, k: i32) -> i32 {
letmut ans =0;
for&a in&nums1 {
for&b in&nums2 {
if a % (b * k) ==0 {
ans +=1;
}
}
}
ans
}
}
1
2
3
4
5
6
7
8
9
10
11
classSolution {
numberOfPairs(nums1: number[], nums2: number[], k: number):number {
letans=0;
for (constaofnums1) {
for (constbofnums2) {
if (a% (b*k) ===0) ans++;
}
}
returnans;
}
}