POJ 2109 Power of Cryptography

POJ 2109 Power of Cryptography

[★★☆☆☆]高精度 二分 神奇的题目

  • 题目大意:

    给n, p求k使得 k^n=p。

  • 输入格式:

    n p

  • 输出格式:

    k

  • 样例

    输入:
    2 16
    3 27
    7 4357186184021382204544
    输出:
    4
    3
    1234

  • 解题思路:

    并不知道出题人的本意是啥。。大概是高精度+二分,不过double + 二分也行。
    不过看到大神给出了BUG级的解法。
    double居然这么好用,学到了。。

  • 代码

#include <iostream>
#include <cmath>

using namespace std;

int main() {
    double n, p;
    while (cin >> n >> p) {
        cout << pow(p, 1.0/n) << endl;
    }

    return 0;
}


你可能感兴趣的:(poj)