code: def _extgcd(a: int, b: int) -> tuple[int, int]:
      # Return (g, x) with g = gcd(a, b), ax + by = g - ax.
  
      # c - ax - by = 0  ...  (1)
      # d - au - bv = 0  ...  (2)
      c, d = a, b
      x, u = 1, 0
      # y, v = 0, 1
  
      # Apply Euclid's algorithm to (c, d)
      while d:
          r = c // d
          # (1), (2) = (2), (1) - (2) * r
          c, d = d, c - d * r
          x, u = u, x - u * r
          # y, v = v, y - u * r
  
      return c, x
  
file_path: cupy/cupyx/distributed/array/_index_arith.py
imports: import typing
  from typing import Any, Optional
label_desc: Use image node_id 1 for calling a global function with example usage: _extgcd(a, b) and returns: c,  x