


from math import pow




def     UpperCamelCase    (      _a       ,		_a       ,		_a       ,		_a       ,		_a       ,		)					->							List[Any]:
     '''simple docstring'''





     if current_sum == needed_sum:
          # If the sum of the powers is equal to needed_sum, then we have a solution.
          solutions_count += 1
          return current_sum, solutions_count

     lowercase_       :Optional[Any]     =       int(pow(UpperCamelCase__       ,		UpperCamelCase__		)		)
     if current_sum + i_to_n <= needed_sum:
          # If the sum of the powers is less than needed_sum, then continue adding powers.
          current_sum += i_to_n
          lowercase_    ,      lowercase_       :Optional[Any]     =       backtrack(
              UpperCamelCase__       ,		UpperCamelCase__       ,		current_number + 1       ,		UpperCamelCase__       ,		UpperCamelCase__		)
          current_sum -= i_to_n
     if i_to_n < needed_sum:
          # If the power of i is less than needed_sum, then try with the next power.
          lowercase_    ,      lowercase_       :Union[str, Any]     =       backtrack(
              UpperCamelCase__       ,		UpperCamelCase__       ,		current_number + 1       ,		UpperCamelCase__       ,		UpperCamelCase__		)
     return current_sum, solutions_count




def     UpperCamelCase    (      _a       ,		_a		)					->							Dict:
     '''simple docstring'''





     if not (1 <= needed_sum <= 1_0_0_0 and 2 <= power <= 1_0):
          raise ValueError(
              '''Invalid input\n'''
              '''needed_sum must be between 1 and 1000, power between 2 and 10.'''		)

     return backtrack(UpperCamelCase__       ,		UpperCamelCase__       ,		1       ,		0       ,		0		)[1]  # Return the solutions_count


if __name__ == "__main__":
   import doctest

   doctest.testmod()





from __future__ import annotations




def     UpperCamelCase    (      _a       ,		_a = None       ,		_a = None		)					->							None:
     '''simple docstring'''





     if start is None:
          lowercase_       :str     =       0

     if end is None:
          lowercase_       :str     =       len(_a		) - 1

     if start >= end:
          return

     lowercase_       :Dict     =       (start + end) // 2

     slowsort(_a       ,		_a       ,		_a		)
     slowsort(_a       ,		mid + 1       ,		_a		)

     if sequence[end] < sequence[mid]:
          lowercase_    ,      lowercase_       :List[Any]     =       sequence[mid], sequence[end]

     slowsort(_a       ,		_a       ,		end - 1		)


if __name__ == "__main__":
   from doctest import testmod

   testmod()

