К списку задач
Средне Решено: 0 Процент решений: 0%

Raise a Fraction to a Real Power

Raise a positive fraction to a real-valued exponent.

Чему вы научитесь

  • Raise a fraction to a real exponent
  • Work with floating-point results
  • Keep results within tolerance

Условие

Показать перевод

Interpret numerator / denominator as a positive rational number, then raise it to power. This task returns a real number rather than an exact fraction; it covers the real-exponent part of the Rational Numbers reference.

Implement rational_to_real_power(numerator, denominator, power).

Input

numerator: The positive numerator.

denominator: The positive denominator.

power: The real-valued exponent.

Output

Return (numerator / denominator) raised to power.

Ограничения

1 ≤ numerator, denominator ≤ 100. −6 ≤ power ≤ 6, with at most two decimal places. Answers are accepted within absolute or relative error 0.000001.

Примеры

Пример 1
Ввод:
power = 0.5
numerator = 9
denominator = 4

Ожидаемый вывод:
expected = 1.5
Ввод:
double power = 0.5;
long long numerator = 9;
long long denominator = 4;

Ожидаемый вывод:
double expected = 1.5;
Ввод:
double power = 0.5;
long numerator = 9;
long denominator = 4;

Ожидаемый вывод:
double expected = 1.5;

Пояснение

An exponent of 0.5 takes the positive square root: √(9/4) = 3/2 = 1.5.

Пример 2
Ввод:
power = -1.0
numerator = 2
denominator = 5

Ожидаемый вывод:
expected = 2.5
Ввод:
double power = -1.0;
long long numerator = 2;
long long denominator = 5;

Ожидаемый вывод:
double expected = 2.5;
Ввод:
double power = -1.0;
long numerator = 2;
long denominator = 5;

Ожидаемый вывод:
double expected = 2.5;

Пояснение

The exponent −1 takes the reciprocal: 5/2 = 2.5.

Как подступиться

Сначала попробуйте сами, затем открывайте подсказки по одной.

Подсказка 1

Treat the fraction as one positive real value before applying the exponent.

Подсказка 2

Use floating-point exponentiation directly, since the answer is approximate.

Подсказка 3

Be careful with negative and fractional-looking exponents, and keep enough precision for the tolerance.

Ожидаемая сложность

O(1) time, O(1) extra space

Ссылки

Это задание адаптировано для CodeUtility. Следуйте условию и ограничениям выше.

Учитесь у других

Решения сообщества

Пока нет опубликованных решений. Решите задание, чтобы поделиться первым.