




def 					UpperCAmelCase__     (   lowerCamelCase      ):

  # bit count represents no. of bits in the gray code
  if bit_count < 0:
    raise ValueError("The given input must be positive"      )

  # get the generated string sequence
  lowercase			:Optional[Any]							=  gray_code_sequence_string(lowerCamelCase      )
  #
  # convert them to integers
  for i in range(len(lowerCamelCase      )      ):
    lowercase			:str							=  int(sequence[i],	2      )

  return sequence



def 					UpperCAmelCase__     (   lowerCamelCase      ):

  # The approach is a recursive one
  # Base case achieved when either n = 0 or n=1
  if bit_count == 0:
    return ["0"]

  if bit_count == 1:
    return ["0", "1"]

  lowercase			:List[str]							=  1 << bit_count  # defines the length of the sequence
  # 1<< n is equivalent to 2^n

  # recursive answer will generate answer for n-1 bits
  lowercase			:Optional[int]							=  gray_code_sequence_string(bit_count - 1      )

  lowercase			:int							=  []

  # append 0 to first half of the smaller sequence generated
  for i in range(seq_len // 2      ):
    lowercase			:Tuple							=  "0" + smaller_sequence[i]
    sequence.append(lowerCamelCase      )

  # append 1 to second half ... start from the end of the list
  for i in reversed(range(seq_len // 2      )      ):
    lowercase			:Optional[int]							=  "1" + smaller_sequence[i]
    sequence.append(lowerCamelCase      )

  return sequence


if __name__ == "__main__":
     import doctest

     doctest.testmod()









import math
import sys



def 					UpperCAmelCase__     (   lowerCamelCase      ):
  if number != int(lowerCamelCase      ):
    raise ValueError("the value of input must be a natural number"      )
  if number < 0:
    raise ValueError("the value of input must not be a negative number"      )
  if number == 0:
    return 1
  lowercase			:Dict							=  [-1] * (number + 1)
  lowercase			:Optional[Any]							=  0
  for i in range(1,	number + 1      ):
    lowercase			:Optional[int]							=  sys.maxsize
    lowercase			:Any							=  int(math.sqrt(lowerCamelCase      )      )
    for j in range(1,	root + 1      ):
      lowercase			:Any							=  1 + answers[i - (j**2)]
      lowercase			:Dict							=  min(lowerCamelCase,	lowerCamelCase      )
    lowercase			:Union[str, Any]							=  answer
  return answers[number]


if __name__ == "__main__":
     import doctest

     doctest.testmod()



