fork download
  1. import java.util.*;
  2.  
  3. public class Main {
  4. public static void main(String[] args) {
  5. Scanner sc = new Scanner(System.in);
  6. int n = sc.nextInt();
  7.  
  8. int[] a = new int[n + 1];
  9. int[] b = new int[n + 1];
  10. Map<Integer, Integer> ma = new HashMap<>();
  11. Map<Integer, Integer> mb = new HashMap<>();
  12.  
  13. for (int i = 1; i <= n; i++) {
  14. a[i] = sc.nextInt();
  15. ma.put(a[i], ma.getOrDefault(a[i], 0) + 1);
  16. }
  17.  
  18. for (int i = 1; i <= n; i++) {
  19. b[i] = sc.nextInt();
  20. mb.put(b[i], mb.getOrDefault(b[i], 0) + 1);
  21. }
  22.  
  23. int res = 0;
  24. for (Map.Entry<Integer, Integer> e : ma.entrySet()) {
  25. int x = e.getKey(), cnt = 0, mul = x;
  26. while (mul <= 1_000_000) {
  27. cnt += mb.getOrDefault(mul, 0);
  28. mul += x;
  29. }
  30. res += cnt * ma.get(x);
  31. }
  32.  
  33. System.out.println(res);
  34. }
  35. }
  36.  
Success #stdin #stdout 0.22s 62180KB
stdin
4
4 4 4 4
4 4 4 4
stdout
16