-
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
package com.fishercoder.solutions.fourththousand;
import java.util.HashMap;
import java.util.Map;
public class _3164 {
public static class Solution1 {
public long numberOfPairs(int[] nums1, int[] nums2, int k) {
long count = 0;
Map<Integer, Integer> map = new HashMap<>();
for (int num : nums2) {
int product = num * k;
map.put(product, map.getOrDefault(product, 0) + 1);
}
for (int num : nums1) {
for (int j = 1; j * j <= num; j++) {
if (num % j == 0) {
if (map.containsKey(j)) {
count += map.get(j);
}
int division = num / j;
if (j != division && map.containsKey(division)) {
count += map.get(division);
}
}
}
}
return count;
}
}
}