POJ-1730(pow精度wa到吐血)(Perfect Pth Powers)

int main()
{
    double n;
    int i;
    while (scanf("%lf", &n) == 1 && n) {
        int tag = 0;
        if (n < 0) {
            tag = 1;
            n = -n;
        }
        if (n == 1) {
            printf("1\n");
            continue;
        }
        for (i = 32; i >= 1; --i) {
            if (tag == 1 && i % 2 == 0) continue;
            ll t = (ll)pow(n, 1.0 / i);
            if (MY_ABS(pow(t * 1.0, i) - n) < 1e-12 || MY_ABS(pow((t - 1) * 1.0, i) - n) < 1e-12 || MY_ABS(pow((t + 1) * 1.0, i) - n) < 1e-12) {
                printf("%d\n", i);
                break;
            }
        }
    }
    return 0;
}

你可能感兴趣的:(POJ-1730(pow精度wa到吐血)(Perfect Pth Powers))