code: def test_lucas_sequence():
      def lucas_u(P, Q, length):
          array = [0] * length
          array[1] = 1
          for k in range(2, length):
              array[k] = P * array[k - 1] - Q * array[k - 2]
          return array
  
      def lucas_v(P, Q, length):
          array = [0] * length
          array[0] = 2
          array[1] = P
          for k in range(2, length):
              array[k] = P * array[k - 1] - Q * array[k - 2]
          return array
  
      length = 20
      for P in range(-10, 10):
          for Q in range(-10, 10):
              D = P**2 - 4 * Q
              if D == 0:
                  continue
              us = lucas_u(P, Q, length)
              vs = lucas_v(P, Q, length)
              for n in range(3, 100, 2):
                  for k in range(length):
                      U, V, Qk = _lucas_sequence(n, P, Q, k)
                      assert U == us[k] % n
                      assert V == vs[k] % n
                      assert pow(Q, k, n) == Qk
  
file_path: sympy/sympy/external/tests/test_ntheory.py
imports: from itertools import permutations
  from sympy.external.ntheory import bit_scan1, remove, bit_scan0, is_fermat_prp, is_euler_prp, is_strong_prp, gcdext, _lucas_sequence, is_fibonacci_prp, is_lucas_prp, is_selfridge_prp, is_strong_lucas_prp, is_strong_selfridge_prp, is_bpsw_prp, is_strong_bpsw_prp
  from sympy.testing.pytest import raises
label_desc: Use image node_id 8 for calling a global function with example usage: test_lucas_sequence() and returns: array, array