





"""simple docstring"""





from math import pow


def 			UpperCAmelCase__							(  SCREAMING_SNAKE_CASE     :						int							,						SCREAMING_SNAKE_CASE     :						int							,						SCREAMING_SNAKE_CASE     :						int							,						SCREAMING_SNAKE_CASE     :						int							,						SCREAMING_SNAKE_CASE     :						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

      lowerCAmelCase  						=       int(pow(SCREAMING_SNAKE_CASE							,						SCREAMING_SNAKE_CASE			)			)
      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(
                SCREAMING_SNAKE_CASE							,						SCREAMING_SNAKE_CASE							,						current_number + 1							,						SCREAMING_SNAKE_CASE							,						SCREAMING_SNAKE_CASE			)
            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(
                SCREAMING_SNAKE_CASE							,						SCREAMING_SNAKE_CASE							,						current_number + 1							,						SCREAMING_SNAKE_CASE							,						SCREAMING_SNAKE_CASE			)
      return current_sum, solutions_count


def 			UpperCAmelCase__							(  SCREAMING_SNAKE_CASE     :						int							,						SCREAMING_SNAKE_CASE     :						int			):







      '''simple docstring'''




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

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


if __name__ == "__main__":
       import doctest

       doctest.testmod()










'''simple docstring'''






def 				UpperCamelCase_			(    A__					:   int					):
  '''simple docstring'''





  lowerCAmelCase_			:      Union[str, Any]			=   (1 + 24 * n) ** 0.5
  return ((1 + root) / 6) % 1 == 0







def 				UpperCamelCase_			(    A__					:   int = 50_00					):
  '''simple docstring'''





  lowerCAmelCase_			:      Optional[int]			=   [(i * (3 * i - 1)) // 2 for i in range(1							,    A__					)]
  for i, pentagonal_i in enumerate(A__					):
    for j in range(A__							,    len(A__					)					):
      lowerCAmelCase_			:      int			=   pentagonal_nums[j]
      lowerCAmelCase_			:      Union[str, Any]			=   pentagonal_i + pentagonal_j
      lowerCAmelCase_			:      List[Any]			=   pentagonal_j - pentagonal_i
      if is_pentagonal(A__					) and is_pentagonal(A__					):
        return b

  return -1


if __name__ == "__main__":
  print(F'''{solution() = }''')



