code: def n_order(a, n):
      r"""Returns the order of ``a`` modulo ``n``.
  
      Explanation
      ===========
  
      The order of ``a`` modulo ``n`` is the smallest integer
      ``k`` such that `a^k` leaves a remainder of 1 with ``n``.
  
      Parameters
      ==========
  
      a : integer
      n : integer, n > 1. a and n should be relatively prime
  
      Returns
      =======
  
      int : the order of ``a`` modulo ``n``
  
      Raises
      ======
  
      ValueError
          If `n \le 1` or `\gcd(a, n) \neq 1`.
          If ``a`` or ``n`` is not an integer.
  
      Examples
      ========
  
      >>> from sympy.ntheory import n_order
      >>> n_order(3, 7)
      6
      >>> n_order(4, 7)
      3
  
      See Also
      ========
  
      is_primitive_root
          We say that ``a`` is a primitive root of ``n``
          when the order of ``a`` modulo ``n`` equals ``totient(n)``
  
      """
      a, n = as_int(a), as_int(n)
      if n <= 1:
          raise ValueError("n should be an integer greater than 1")
      a = a % n
      # Trivial
      if a == 1:
          return 1
      if gcd(a, n) != 1:
          raise ValueError("The two numbers should be relatively prime")
      a_order = 1
      for p, e in factorint(n).items():
          pe = p**e
          pe_order = (p - 1) * p ** (e - 1)
          factors = factorint(p - 1)
          if e > 1:
              factors[p] = e - 1
          order = 1
          for px, ex in factors.items():
              x = pow(a, pe_order // px**ex, pe)
              while x != 1:
                  x = pow(x, px, pe)
                  order *= px
          a_order = lcm(a_order, order)
      return int(a_order)
  
imports: from __future__ import annotations
  from sympy.external.gmpy import gcd, lcm, invert, sqrt, legendre, jacobi, kronecker, bit_scan1, remove
  from sympy.polys import Poly
  from sympy.polys.domains import ZZ
  from sympy.polys.galoistools import gf_crt1, gf_crt2, linear_congruence, gf_csolve
  from .primetest import isprime
  from .factor_ import factorint, _perfect_power
  from .modular import crt
  from sympy.utilities.decorator import deprecated
  from sympy.utilities.memoization import recurrence_memo
  from sympy.utilities.misc import as_int
  from sympy.utilities.iterables import iproduct
  from sympy.core.random import _randint, randint
  from itertools import product
label_desc: Use image node_id 1 for calling a global function with example usage: n_order(a, n) and returns: int, int