




"""simple docstring"""




from math import pow



def        a__					(							snake_case__			,					snake_case__			,					snake_case__			,					snake_case__			,					snake_case__			,					)		->   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

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



def        a__					(							snake_case__			,					snake_case__							)		->   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(snake_case__			,					snake_case__			,					1			,					0			,					0							)[1]  # Return the solutions_count


if __name__ == "__main__":
					import doctest

					doctest.testmod()









"""simple docstring"""




from __future__ import annotations

from decimal import Decimal

from numpy import array



def        a__					(							snake_case__							)		->   list[list[float]]:
			lowerCamelCase      =   Decimal

			# Check if the provided matrix has 2 rows and 2 columns
			# since this implementation only works for 2x2 matrices
			if len(snake_case__							) == 2 and len(matrix[0]							) == 2 and len(matrix[1]							) == 2:
						# Calculate the determinant of the matrix
						lowerCamelCase      =   float(
						    d(matrix[0][0]							) * d(matrix[1][1]							) - d(matrix[1][0]							) * d(matrix[0][1]							)							)
						if determinant == 0:
									raise ValueError("""This matrix has no inverse."""							)

						# Creates a copy of the matrix with swapped positions of the elements
						lowerCamelCase      =   [[0.0, 0.0], [0.0, 0.0]]
						lowerCamelCase ,  lowerCamelCase      =   matrix[1][1], matrix[0][0]
						lowerCamelCase ,  lowerCamelCase      =   -matrix[1][0], -matrix[0][1]

						# Calculate the inverse of the matrix
						return [
						    [(float(d(snake_case__							)							) / determinant) or 0.0 for n in row] for row in swapped_matrix
						]
			elif (
			    len(snake_case__							) == 3
			    and len(matrix[0]							) == 3
			    and len(matrix[1]							) == 3
			    and len(matrix[2]							) == 3
			):
						# Calculate the determinant of the matrix using Sarrus rule
						lowerCamelCase      =   float(
						    (
						        (d(matrix[0][0]							) * d(matrix[1][1]							) * d(matrix[2][2]							))
						        + (d(matrix[0][1]							) * d(matrix[1][2]							) * d(matrix[2][0]							))
						        + (d(matrix[0][2]							) * d(matrix[1][0]							) * d(matrix[2][1]							))
						    )
						    - (
						        (d(matrix[0][2]							) * d(matrix[1][1]							) * d(matrix[2][0]							))
						        + (d(matrix[0][1]							) * d(matrix[1][0]							) * d(matrix[2][2]							))
						        + (d(matrix[0][0]							) * d(matrix[1][2]							) * d(matrix[2][1]							))
						    )							)
						if determinant == 0:
									raise ValueError("""This matrix has no inverse."""							)

						# Creating cofactor matrix
						lowerCamelCase      =   [
						    [d(0.0							), d(0.0							), d(0.0							)],
						    [d(0.0							), d(0.0							), d(0.0							)],
						    [d(0.0							), d(0.0							), d(0.0							)],
						]
						lowerCamelCase      =   (d(matrix[1][1]							) * d(matrix[2][2]							)) - (
						    d(matrix[1][2]							) * d(matrix[2][1]							)
						)
						lowerCamelCase      =   -(
						    (d(matrix[1][0]							) * d(matrix[2][2]							)) - (d(matrix[1][2]							) * d(matrix[2][0]							))
						)
						lowerCamelCase      =   (d(matrix[1][0]							) * d(matrix[2][1]							)) - (
						    d(matrix[1][1]							) * d(matrix[2][0]							)
						)
						lowerCamelCase      =   -(
						    (d(matrix[0][1]							) * d(matrix[2][2]							)) - (d(matrix[0][2]							) * d(matrix[2][1]							))
						)
						lowerCamelCase      =   (d(matrix[0][0]							) * d(matrix[2][2]							)) - (
						    d(matrix[0][2]							) * d(matrix[2][0]							)
						)
						lowerCamelCase      =   -(
						    (d(matrix[0][0]							) * d(matrix[2][1]							)) - (d(matrix[0][1]							) * d(matrix[2][0]							))
						)
						lowerCamelCase      =   (d(matrix[0][1]							) * d(matrix[1][2]							)) - (
						    d(matrix[0][2]							) * d(matrix[1][1]							)
						)
						lowerCamelCase      =   -(
						    (d(matrix[0][0]							) * d(matrix[1][2]							)) - (d(matrix[0][2]							) * d(matrix[1][0]							))
						)
						lowerCamelCase      =   (d(matrix[0][0]							) * d(matrix[1][1]							)) - (
						    d(matrix[0][1]							) * d(matrix[1][0]							)
						)

						# Transpose the cofactor matrix (Adjoint matrix)
						lowerCamelCase      =   array(snake_case__							)
						for i in range(3							):
									for j in range(3							):
												lowerCamelCase      =   cofactor_matrix[j][i]

        # Inverse of the matrix using the formula (1/determinant) * adjoint matrix
						lowerCamelCase      =   array(snake_case__							)
						for i in range(3							):
									for j in range(3							):
												inverse_matrix[i][j] /= d(snake_case__							)

        # Calculate the inverse of the matrix
						return [[float(d(snake_case__							)							) or 0.0 for n in row] for row in inverse_matrix]
			raise ValueError("""Please provide a matrix of size 2x2 or 3x3."""							)



