【2017ACM-ICPC广西邀请赛】A Math Problem

【2017ACM-ICPC广西邀请赛】A Math Problem

问题链接:https://vjudge.net/problem/HDU-6182

注意:k为15时超过1e18

方法:十分简单的一道题,直接枚举就好。

Solution:

#include <iostream>

using namespace std;

typedef unsigned long long ULL;

ULL fastPow(ULL a, ULL b) {
    ULL ret = 1;
    for (; b; b >>= 1) {
        if (b & 1) ret *= a;
        a *= a;
    }
    return ret;
}

int main(void) {
    ULL n;
    while (cin >> n) {
        ULL k;
        for (k = 1; k <= 15; k++)
            if (fastPow(k, k) > n) break;
        cout << k - 1 << endl;
    }
    return 0;
}