code: def _crt(
      a1: int, n1: int, a2: int, n2: int
  ) -> Optional[tuple[int, int]]:
      # Return x, n with x == a1 (mod n1), x == a2 (mod n2), n == lcm(n1, n2).
      # Choose the minimum value for x with x >= max(a1, a2). Return None if no
      # solution exists.
      # Reference: https://en.wikipedia.org/wiki/Chinese_remainder_theorem#Existence_(constructive_proof)  # NOQA
  
      # m1 * n1 + m2 * n2 == g
      g, m1 = _extgcd(n1, n2)
  
      # x == a1 == a2 (mod g)
      if (a2 - a1) % g != 0:
          return None
  
      n = n1 * (n2 // g)
  
      # x = a1 + (a2 - a1) // g * m1 * n1 % n
      x = a1 + (a2 - a1) // g * m1 % (n // n1) * n1
  
      if x < a2:
          x += ((a2 - x - 1) // n + 1) * n
  
      return x, n
  
file_path: cupy/cupyx/distributed/array/_index_arith.py
imports: import typing
  from typing import Any, Optional
label_desc: Use image node_id 2 for calling a global function with example usage: _crt(a1, n1, a2, n2) and returns: x,  n, None