






"""simple docstring"""


def        UpperCAmelCase      (					a__ ):





						'''simple docstring'''






						lowerCAmelCase   :Optional[int]						=			(1 + 24 * n) ** 0.5
						return ((1 + root) / 6) % 1 == 0


def        UpperCAmelCase      (					a__ = 50_00 ):





						'''simple docstring'''






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

						return -1


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


'''simple docstring'''







from math import pow
def    UpperCAmelCase__     (   UpperCAmelCase__,							UpperCAmelCase__,							UpperCAmelCase__,							UpperCAmelCase__,							UpperCAmelCase__,							)      ->      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

       A_						       =   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
              A_       ,      A_						       =   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.
              A_       ,      A_						       =   backtrack(
                  UpperCAmelCase__,							UpperCAmelCase__,							current_number + 1,							UpperCAmelCase__,							UpperCAmelCase__					)
       return current_sum, solutions_count
def    UpperCAmelCase__     (   UpperCAmelCase__,							UpperCAmelCase__					)      ->      int:
       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(UpperCAmelCase__,							UpperCAmelCase__,							1,							0,							0					)[1]  # Return the solutions_count


if __name__ == "__main__":
      import doctest

      doctest.testmod()
