def pi_hex_digits(n, prec=14):
 (n, prec) = (as_int(n), as_int(prec))
 if (n < 0):
  raise ValueError('n cannot be negative')
 if (prec == 0):
  return ''
 n -= 1
 a = [4, 2, 1, 1]
 j = [1, 4, 5, 6]
 D = _dn(n, prec)
 x = ((+ ((((a[0] * _series(j[0], n, prec)) - (a[1] * _series(j[1], n, prec))) - (a[2] * _series(j[2], n, prec))) - (a[3] * _series(j[3], n, prec)))) & ((16 ** D) - 1))
 s = (('%0' + ('%ix' % prec)) % (x // (16 ** (D - prec))))
 return s

def pi_hex_digits ( n , prec = 14 ) : ( n , prec ) = ( as_int ( n ) , as_int ( prec ) ) if ( n < 0 ) : raise ValueError ( 'n cannot be negative' ) if ( prec == 0 ) : return '' n -= 1 a = [ 4 , 2 , 1 , 1 ] j = [ 1 , 4 , 5 , 6 ] D = _dn ( n , prec ) x = ( ( + ( ( ( ( a [ 0 ] * _series ( j [ 0 ] , n , prec ) ) - ( a [ 1 ] * _series ( j [ 1 ] , n , prec ) ) ) - ( a [ 2 ] * _series ( j [ 2 ] , n , prec ) ) ) - ( a [ 3 ] * _series ( j [ 3 ] , n , prec ) ) ) ) & ( ( 16 ** D ) - 1 ) ) s = ( ( '%0' + ( '%ix' % prec ) ) % ( x // ( 16 ** ( D - prec ) ) ) ) return s
returns a string containing prec digits starting at the nth digit of pi in hex .