ACM (TJU) : 2526


#include <iostream>
#include <cmath>
using namespace std;

int main ()
{
    double b, n;

    while ( cin >> b >> n) {

        if ( b == 0 && n == 0 )
        return 0;

        double power = pow (b, 1 / n);

        double x = floor (power);
        double y = ceil (power);

        double diff1 = b - pow (x, n);

        double diff2 = pow (y, n) - b;

        if ( diff1 > diff2 )
        cout << (int)y << endl;

        else
        cout << (int)x << endl;
    }

    return 0;
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s