




'''simple docstring'''

from math import pow


def 		__magic_name__    (	__UpperCAmelCase,      __UpperCAmelCase,      __UpperCAmelCase,      __UpperCAmelCase,      __UpperCAmelCase,      )		->					tuple[int, int]:

					'''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

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


def 		__magic_name__    (	__UpperCAmelCase,      __UpperCAmelCase	)		->					int:

					'''simple docstring'''

					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"""
def 						__a   (	_SCREAMING_SNAKE_CASE		,     _SCREAMING_SNAKE_CASE   )	->int:
  while a != 0:
    a__							,    a__:     List[str]										=	b % a, a
  return b







def 						__a   (	_SCREAMING_SNAKE_CASE		,     _SCREAMING_SNAKE_CASE   )	->int:
  if gcd(_SCREAMING_SNAKE_CASE		,     _SCREAMING_SNAKE_CASE   ) != 1:
    a__:     Dict										=	F'mod inverse of {a!r} and {m!r} does not exist'
    raise ValueError(_SCREAMING_SNAKE_CASE   )
  a__							,    a__							,    a__:     Union[str, Any]										=	1, 0, a
  a__							,    a__							,    a__:     Any										=	0, 1, m
  while va != 0:
    a__:     int										=	ua // va
    a__							,    a__							,    a__							,    a__							,    a__							,    a__:     Any										=	(ua - q * va), (ua - q * va), (ua - q * va), va, va, va
  return ua % m


