Recursive Power

Lab C Intermediate 20 points

Write a recursive double power(double b, int e) using b^e = b^(e/2) squared, and print the result with 4 decimals. Negative exponents mean 1 / b^(-e).

Input

One line: b e.

Output

One line.

Example

Input

2 10

Output

1024.0000
Sample input available Sample output available
Editor
C

Hints

Compute the half power once and reuse it.

Solution explanation

Halving the exponent means only about log₂(e) calls.

Show solution
#include <stdio.h>

double power(double b, int e) {
    if (e == 0) return 1;
    if (e < 0) return 1 / power(b, -e);
    double half = power(b, e / 2);
    if (e % 2 == 0) return half * half;
    return half * half * b;
}

int main() {
    double b;
    int e;
    scanf("%lf %d", &b, &e);
    printf("%.4f\n", power(b, e));
    return 0;
}
Output
Answer
HOME LEARN COMMUNITY DASHBOARD