code: def power_recur(a: int, n: int, mod: int = None):
      """
      Recursive version of binary exponentiation
  
      Calculate a ^ n
      if mod is specified, return the result modulo mod
  
      Time Complexity :  O(log(n))
      Space Complexity : O(log(n))
      """
      if n == 0:
          ans = 1
      elif n == 1:
          ans = a
      else:
          ans = power_recur(a, n // 2, mod)
          ans = ans * ans
          if n % 2:
              ans = ans * a
      if mod:
          ans %= mod
      return ans
  
label_desc: Use image node_id 2 for calling a global function with example usage: power_recur(a, n, mod) and returns: ans