

from math import pow

def       a__					(		UpperCAmelCase							:      Optional[int]    ,			UpperCAmelCase							:      Any    ,			UpperCAmelCase							:      Any    ,			UpperCAmelCase							:      List[str]    ,			UpperCAmelCase							:      Tuple    ,			)  ->						tuple[int, int]:
  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

  UpperCAmelCase	:							Tuple						=			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
    UpperCAmelCase			,						UpperCAmelCase	:							Optional[int]						=			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.
    UpperCAmelCase			,						UpperCAmelCase	:							Dict						=			backtrack(
        UpperCAmelCase    ,			UpperCAmelCase    ,			current_number + 1    ,			UpperCAmelCase    ,			UpperCAmelCase      )
  return current_sum, solutions_count

def       a__					(		UpperCAmelCase							:      str    ,			UpperCAmelCase							:      List[Any]      )  ->						int:
  if not (1 <= needed_sum <= 1_000 and 2 <= power <= 10):
    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 ..utils import DummyObject, requires_backends





class  __UpperCAmelCase					(	metaclass=lowerCamelCase__						):
   UpperCamelCase       					=					["""onnx"""]



   def __init__(							self							:					int,		*__A							:					Optional[Any],		**__A							:					Dict						):
     requires_backends(self,		['''onnx''']						)



   @classmethod
   def 	__magic_name__   (							cls							:					Any,		*__A							:					Any,		**__A							:					Dict						):
     requires_backends(cls,		['''onnx''']						)





   @classmethod
   def 	__magic_name__   (							cls							:					Tuple,		*__A							:					List[str],		**__A							:					List[str]						):
     requires_backends(cls,		['''onnx''']						)





