def prevprime(n):
 from sympy.functions.elementary.integers import ceiling
 n = int(ceiling(n))
 if (n < 3):
  raise ValueError('no preceding primes')
 if (n < 8):
  return {3: 2, 4: 3, 5: 3, 6: 5, 7: 5}[n]
 if (n <= sieve._list[(-1)]):
  (l, u) = sieve.search(n)
  if (l == u):
   return sieve[(l - 1)]
  else:
   return sieve[l]
 nn = (6 * (n // 6))
 if ((n - nn) <= 1):
  n = (nn - 1)
  if isprime(n):
   return n
  n -= 4
 else:
  n = (nn + 1)
 while 1:
  if isprime(n):
   return n
  n -= 2
  if isprime(n):
   return n
  n -= 4

def prevprime ( n ) : from sympy . functions . elementary . integers import ceiling n = int ( ceiling ( n ) ) if ( n < 3 ) : raise ValueError ( 'no preceding primes' ) if ( n < 8 ) : return { 3 : 2 , 4 : 3 , 5 : 3 , 6 : 5 , 7 : 5 } [ n ] if ( n <= sieve . _list [ ( - 1 ) ] ) : ( l , u ) = sieve . search ( n ) if ( l == u ) : return sieve [ ( l - 1 ) ] else : return sieve [ l ] nn = ( 6 * ( n // 6 ) ) if ( ( n - nn ) <= 1 ) : n = ( nn - 1 ) if isprime ( n ) : return n n -= 4 else : n = ( nn + 1 ) while 1 : if isprime ( n ) : return n n -= 2 if isprime ( n ) : return n n -= 4
return the largest prime smaller than n .