2012-07-14 08:34:48Morris

[UVA][Math] 10509 - R U Kidding Mr. Feynman?

Problem A
R U Kidding Mr. Feynman?
Input: Standard Input

Output: Standard Output

Richard P. Feynman was amusician, artist, scientist, teacher and Nobel lauriet. He contributed to the developmentof the atomic bomb, expanded the understanding of quantumelectrodynamics,translated Mayan hieroglyphics, and cut to the heart of the Challengerdisaster. But beyond all of that, Richard Feynman was a unique andmulti-faceted individual and he was famous for his unbelievable stories,unusual life style and his popular books and lectures on mathematics andphysics. Once, in Brazil, Feynman got into a kind of a competition with anative to see who could do faster simple aritmethics, Feynman or an abacus (aka an manual calculator machine)! Feynman lost in operations such as additionand multiplication but he won in cubic roots. Given the number 1729.03he got the result of 12.002 at the end of a few seconds while hisoponent got 12.0!



Considering an square of side 'a', with area 'a*a', if you doa small increment of 'dx' on each side , you will get a square with areaof the square with side 'a' (Light gray) plus the area of the two smallrips (Medium Gray) on top plus the area of the small square(dark gray). Sincethis is only an approximated method, we can ignore this small area ((dx)²).Then just get value of dx, and substitute in (1).

Example,

To calculate square root of 17, as Feynman has an excelent memory, he knows'all' perfect squares (as well cubes), he knows that 4*4 = 16then he just use the method above and calculate 4+1/8 that equals 4.125(not very bad as  square root of 17= 4.123...)

As Feynman is verylazy, and he doesn't like subtractions at all, he doesn't use negative dx....(it's boring.. )

Your Task is to generalize this procedure to the cubic root, and HELP FEYNMAN!(Just do it, What do you care what other people think?)

Input 

The input contains a positive floating-point number perline in the inteval [1…1000000] (inclusive). The last line of the inputfile contains a number 0 (zero), This zero should not be processed.

 

Output 

For each line of input print the value of the cubic rootapproximated by the method explained above. Print the value rounded upto fourdigits after the decimal point.

 

Sample Input                             Output for SampleInput

1729.0300
64.0000
63.9990
0
12.0024
4.0000

4.3703


Problemsetter: Rui André A. Ferreira 


#include <stdio.h>
#include <math.h>

int main() {
    double f;
    while(scanf("%lf", &f) == 1 && f) {
        double a = floor(pow(f, 1/3.0)+1e-6);
        double dx = (f-a*a*a)/3.0/a/a;
        printf("%.4lf\n", a+dx);
    }
    return 0;
}