


from math import pow
def 				__lowerCamelCase						( UpperCAmelCase_						:		int ,  UpperCAmelCase_						:		int ,  UpperCAmelCase_						:		int ,  UpperCAmelCase_						:		int ,  UpperCAmelCase_						:		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

      a						:List[Any] 							=       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						:List[Any] 							=       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						:List[str] 							=       backtrack(
                UpperCAmelCase_ ,  UpperCAmelCase_ ,  current_number + 1 ,  UpperCAmelCase_ ,  UpperCAmelCase_						)
      return current_sum, solutions_count
def 				__lowerCamelCase						( UpperCAmelCase_						:		int ,  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()












from __future__ import annotations

from decimal import Decimal
from math import *  # noqa: F403

from sympy import diff





def      lowerCAmelCase_ (       __a	,    __a	,    __a = 10**-10		)     ->		float:







  """simple docstring"""





  lowerCamelCase__:      str			  =a
  while True:
    lowerCamelCase__:      Optional[Any]			  =Decimal(__a		) - (
        Decimal(eval(__a		)		) / Decimal(eval(str(diff(__a		)		)		)		)  # noqa: S307
    )
    # This number dictates the accuracy of the answer
    if abs(eval(__a		)		) < precision:  # noqa: S307
      return float(__a		)


# Let's Execute
if __name__ == "__main__":
     # Find root of trigonometric function
     # Find value of pi
     print(f'The root of sin(x) = 0 is {newton_raphson("sin(x)", 2)}')
     # Find root of polynomial
     print(f'The root of x**2 - 5*x + 2 = 0 is {newton_raphson("x**2 - 5*x + 2", 0.4)}')
     # Find Square Root of 5
     print(f'The root of log(x) - 1 = 0 is {newton_raphson("log(x) - 1", 2)}')
     # Exponential Roots
     print(f'The root of exp(x) - 1 = 0 is {newton_raphson("exp(x) - 1", 0)}')

