1
// The condition given to us is (a*b % k==0)2
// So we can rewrite the above condition that if any factor of k is present in a and any other3
// factor of k is present in b then their multiplication will be divisble by k5
// so gcd(a,k) * gcd(b,k) % k==08
public long countPairs(int[] nums, int k) {10
HashMap<Integer, Integer> hm = new HashMap<>();11
for (int val : nums) {12
int gcd1 = gcd(val, k);14
for (int gcd2 : hm.keySet()) {15
if ((long) gcd1 * gcd2 % k == 0) {20
hm.put(gcd1, hm.getOrDefault(gcd1, 0) + 1);26
// function to calculate gcd28
public int gcd(int n1, int n2) {29
while (n1 % n2 != 0) {