



from math import pow






def 				A				(					_lowerCamelCase				, _lowerCamelCase				, _lowerCamelCase				, _lowerCamelCase				, _lowerCamelCase				, ):





							'''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     :							Any    =    int(pow(_lowerCamelCase				, _lowerCamelCase  )  )
							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     :							Any    =    backtrack(
														    _lowerCamelCase				, _lowerCamelCase				, current_number + 1				, _lowerCamelCase				, _lowerCamelCase  )
														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     :							List[Any]    =    backtrack(
														    _lowerCamelCase				, _lowerCamelCase				, current_number + 1				, _lowerCamelCase				, _lowerCamelCase  )
							return current_sum, solutions_count






def 				A				(					_lowerCamelCase				, _lowerCamelCase  ):





							'''simple docstring'''




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

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


if __name__ == "__main__":
						import doctest

						doctest.testmod()


"""simple docstring"""





def 	__a     (		__lowerCamelCase = 3,		__lowerCamelCase = 7,		__lowerCamelCase = 100_0000  ):
   UpperCAmelCase_					:					Dict			     =    0
   UpperCAmelCase_					:					List[Any]			     =    1

   for current_denominator in range(1,		limit + 1  ):
      UpperCAmelCase_					:					Dict			     =    current_denominator * numerator // denominator
      if current_denominator % denominator == 0:
         current_numerator -= 1
      if current_numerator * max_denominator > current_denominator * max_numerator:
         UpperCAmelCase_					:					List[Any]			     =    current_numerator
         UpperCAmelCase_					:					Optional[int]			     =    current_denominator
   return max_numerator


if __name__ == "__main__":
    print(solution(numerator=3, denominator=7, limit=1_000_000))


