





from math import pow

def   a_    ( lowerCAmelCase_      :			Dict,	lowerCAmelCase_      :			int,	lowerCAmelCase_      :			List[str],	lowerCAmelCase_      :			str,	lowerCAmelCase_      :			Dict,	):
   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

   __lowerCAmelCase								=	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
      __lowerCAmelCase	,	__lowerCAmelCase								=	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.
      __lowerCAmelCase	,	__lowerCAmelCase								=	backtrack(
          UpperCamelCase_,	UpperCamelCase_,	current_number + 1,	UpperCamelCase_,	UpperCamelCase_	)
   return current_sum, solutions_count

def   a_    ( lowerCAmelCase_      :			Union[str, Any],	lowerCAmelCase_      :			Any	):
   if not (1 <= needed_sum <= 1000 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()



"""simple docstring"""





__magic_name__       =			"Tobias Carryer"

from time import time
class 						SCREAMING_SNAKE_CASE_ :




		"""simple docstring"""





		def __init__(     self							,  lowerCAmelCase__							,  lowerCAmelCase__							,  lowerCAmelCase__							,  lowerCAmelCase__=int(time())):  # noqa: B008
				__SCREAMING_SNAKE_CASE            = multiplier
				__SCREAMING_SNAKE_CASE            = increment
				__SCREAMING_SNAKE_CASE            = modulo
				__SCREAMING_SNAKE_CASE            = seed




		def 	snake_case_     (     self):
				__SCREAMING_SNAKE_CASE            = (self.multiplier * self.seed + self.increment) % self.modulo
				return self.seed


if __name__ == "__main__":
							# Show the LCG in action.
							__magic_name__       =			LinearCongruentialGenerator(1664525, 1013904223, 2 << 31)
							while True:
														print(lcg.next_number())




