Skip to content

Commit 3353523

Browse files
add 3164
1 parent 88ed746 commit 3353523

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.fishercoder.solutions;
2+
3+
import java.util.HashMap;
4+
import java.util.Map;
5+
6+
public class _3164 {
7+
public static class Solution1 {
8+
public long numberOfPairs(int[] nums1, int[] nums2, int k) {
9+
long count = 0;
10+
Map<Integer, Integer> map = new HashMap<>();
11+
for (int num : nums2) {
12+
int product = num * k;
13+
map.put(product, map.getOrDefault(product, 0) + 1);
14+
}
15+
for (int num : nums1) {
16+
for (int j = 1; j * j <= num; j++) {
17+
if (num % j == 0) {
18+
if (map.containsKey(j)) {
19+
count += map.get(j);
20+
}
21+
int division = num / j;
22+
if (j != division && map.containsKey(division)) {
23+
count += map.get(division);
24+
}
25+
}
26+
}
27+
}
28+
return count;
29+
}
30+
}
31+
}

0 commit comments

Comments
 (0)