- Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy path_3164.java
31 lines (29 loc) · 1 KB
/
_3164.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
packagecom.fishercoder.solutions.fourththousand;
importjava.util.HashMap;
importjava.util.Map;
publicclass_3164 {
publicstaticclassSolution1 {
publiclongnumberOfPairs(int[] nums1, int[] nums2, intk) {
longcount = 0;
Map<Integer, Integer> map = newHashMap<>();
for (intnum : nums2) {
intproduct = num * k;
map.put(product, map.getOrDefault(product, 0) + 1);
}
for (intnum : nums1) {
for (intj = 1; j * j <= num; j++) {
if (num % j == 0) {
if (map.containsKey(j)) {
count += map.get(j);
}
intdivision = num / j;
if (j != division && map.containsKey(division)) {
count += map.get(division);
}
}
}
}
returncount;
}
}
}