Calculate the super root of a number In mathematics, tetration is the next hyper operator after exponentiation, and is defined as iterated exponentiation.

Addition (a succeeded n times)



Multiplication (a added to itself, n times)



Exponentiation (a multiplied by itself, n times)



Tetration (a exponentiated by itself, n times)



The inverse relations of tetration are called the super-root, and the super-logarithm.
Your task is to write a program that, given A and B, prints out the Bnd-order super-root of A.

For example:


if A = 65,536 and B = 4 it prints 2
if A = 7,625,597,484,987 and B = 3 it prints 3


A and B are positive integers and the result must be floating point number with a precision of 5 digits after the decimal point.
The result belongs to the real domain.

Be careful, super-roots may have many solutions.
C — aiming for clarity, didn't attempt to squeeze the code
Considering input:
A: A ∈ ℝ, A ≥ 1.0
B: B ∈ ℕ, B ≥ 1

Then there should usually be only one solution in ℝ, which simplifies the problem considerably.
Code is:
#include &lt;stdlib.h&gt;
#include &lt;stdio.h&gt;
#include &lt;math.h&gt;

#define TOLERANCE    1.0e-09

double tetrate(double, int);

int main(int argc, char **argv)
{
    double target, max, min, mid, working;
    int levels;

    if (argc == 3)
    {
        target = atof(argv[1]); // A
        levels = atoi(argv[2]); // B

        // Shortcut if B == 1
        if (levels == 1)
        {
            printf(&quot;%f\n&quot;, target);
            return 0;
        }

        // Get a first approximation
        max = 2.0;
        while (tetrate(max, levels) &lt; target)
            max *= 2.0;

        min = max / 2.0;

        // printf(&quot;Answer is between %g and %g\n&quot;, min, max);

        // Use bisection to get a closer approximation
        do
        {
            mid = (min + max) / 2.0;
            working = tetrate(mid, levels);
            if (working &gt; target)
                max = mid;
            else if (working &lt; target)
                min = mid;
            else
                break;
        }
        while (max - min &gt; TOLERANCE);

        // printf(&quot;%g: %f = %f tetrate %d\n&quot;, target, tetrate(mid, levels), mid, levels);
        printf(&quot;%f\n&quot;, mid);
    }

    return 0;
}

double tetrate(double d, int i)
{
    double result = d;

    // If the result is already infinite, don't tetrate any more
    while (--i &amp;&amp; isfinite(result))
        result = pow(d, result);

    return result;
}

To compile:
gcc -o tet_root tet_root.c -lm

To run:
./tet_root A B

E.g.:
42
$ ./tet_root 65536 4
2.000000

33
$ ./tet_root 7625597484987 3
3.000000

3π
$ ./tet_root 1.340164183e18 3
3.141593

n(2½) ➙ 2 as n ➙ ∞ ? (well known limit)
$ ./tet_root 2 10
1.416190

$ ./tet_root 2 100
1.414214

$ ./tet_root 2 1000
1.414214

Yes!
n(e1/e) ➙ ∞ as n ➙ ∞ ? (upper bounds)
$ ./tet_root 9.999999999e199 100
1.445700

$ ./tet_root 9.999999999e199 1000
1.444678

$ ./tet_root 9.999999999e199 10000
1.444668

$ ./tet_root 9.999999999e199 100000
1.444668

Cool! (e1/e ≅ 1.44466786101...)