input: from typing import List
  from collections import defaultdict
  from math import isqrt
  def count_valid_pairs(nums1: List[int], nums2: List[int], k: int) -> int:
      """
      You have two integer arrays nums1 and nums2 with lengths n and m respectively. Additionally, you are given a positive number k.
  
      A pair (i, j) is termed valid if nums1[i] is divisible by nums2[j] * k (0 <= i <= n - 1, 0 <= j <= m - 1).
  
      Return the count of all valid pairs.
  
      Examples:
      >>> nums1 = [1, 3, 4], nums2 = [1, 3, 4], k = 1
      5
      >>> nums1 = [1, 2, 4, 12], nums2 = [2, 4], k = 3
      2
  
      Constraints:
      1 <= n, m <= 50
      1 <= nums1[i], nums2[j] <= 50
      1 <= k <= 50
      """
output:     
      count = 0
      for num1 in nums1:
          for num2 in nums2:
              if num1 % (num2 * k) == 0:
                  count += 1
      return count
  