def is_strong_lucas_prp(n):
 from sympy.ntheory.factor_ import trailing
 n = as_int(n)
 if (n == 2):
  return True
 if ((n < 2) or ((n % 2) == 0)):
  return False
 if is_square(n, False):
  return False
 (D, P, Q) = _lucas_selfridge_params(n)
 if (D == 0):
  return False
 s = trailing((n + 1))
 k = ((n + 1) >> s)
 (U, V, Qk) = _lucas_sequence(n, P, Q, k)
 if ((U == 0) or (V == 0)):
  return True
 for r in range(1, s):
  V = (((V * V) - (2 * Qk)) % n)
  if (V == 0):
   return True
  Qk = pow(Qk, 2, n)
 return False

def is_strong_lucas_prp ( n ) : from sympy . ntheory . factor_ import trailing n = as_int ( n ) if ( n == 2 ) : return True if ( ( n < 2 ) or ( ( n % 2 ) == 0 ) ) : return False if is_square ( n , False ) : return False ( D , P , Q ) = _lucas_selfridge_params ( n ) if ( D == 0 ) : return False s = trailing ( ( n + 1 ) ) k = ( ( n + 1 ) >> s ) ( U , V , Qk ) = _lucas_sequence ( n , P , Q , k ) if ( ( U == 0 ) or ( V == 0 ) ) : return True for r in range ( 1 , s ) : V = ( ( ( V * V ) - ( 2 * Qk ) ) % n ) if ( V == 0 ) : return True Qk = pow ( Qk , 2 , n ) return False
strong lucas compositeness test with selfridge parameters .