input: Write a python function to convert a number into words.
  assert num_to_words(5) == "five"
  assert num_to_words(13) == "thirteen"
  assert num_to_words(45) == "forty five"
  assert num_to_words(123) == "one hundred twenty three"
  assert num_to_words(1001) == "one thousand one"
output: def num_to_words(num):
      def one_to_nineteen(n):
          words = ["", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten",
                   "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"]
          return words[n]
  
      def tens(n):
          words = ["", "", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"]
          return words[n]
  
      def two_digits(n):
          if n < 20:
              return one_to_nineteen(n)
          else:
              return tens(n // 10) + ('' if n % 10 == 0 else ' ' + one_to_nineteen(n % 10))
  
      def three_digits(n):
          if n < 100:
              return two_digits(n)
          else:
              return one_to_nineteen(n // 100) + ' hundred' + ('' if n % 100 == 0 else ' ' + two_digits(n % 100))
  
      def num_to_words_rec(n):
          if n < 1000:
              return three_digits(n)
          for denom, word in [(10**9, 'billion'), (10**6, 'million'), (1000, 'thousand')]:
              if n >= denom:
                  return num_to_words_rec(n // denom) + ' ' + word + ('' if n % denom == 0 else ' ' + num_to_words_rec(n % denom))
  
      if num == 0:
          return 'zero'
      return num_to_words_rec(num)