it is natural to implement it using recursion def convert_base num_as_string )def construct_from_base num_as_int base)return ('if num_as_int = else construct_from_base num_as_int /base basestring hexdigits num_as_int base upper ()is_negative num_as_string [ ='-num_as_int functools reduce lambda xcx string hexdigits index ( lower ())num_as_string is_negative :] return ('-if is_negative else ''(' if num_as_int = else construct_from_base num_as_int )the time complexity is ( ( logb ))where is the length of the reasoning is as follows firstwe perform multiply-and-adds to get from then we perform logb multiply and adds to get the result the value is upper-bounded by bn and logb (bn logb