結果

問題 No.1666 累乗数
ユーザー tokusakuraitokusakurai
提出日時 2021-09-03 22:01:38
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,454 ms / 2,000 ms
コード長 2,217 bytes
コンパイル時間 2,101 ms
コンパイル使用メモリ 199,540 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-21 21:49:28
合計ジャッジ時間 19,855 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 97 ms
4,380 KB
testcase_02 AC 150 ms
4,380 KB
testcase_03 AC 177 ms
4,380 KB
testcase_04 AC 191 ms
4,376 KB
testcase_05 AC 1,448 ms
4,376 KB
testcase_06 AC 1,452 ms
4,380 KB
testcase_07 AC 1,448 ms
4,376 KB
testcase_08 AC 1,454 ms
4,380 KB
testcase_09 AC 532 ms
4,376 KB
testcase_10 AC 571 ms
4,380 KB
testcase_11 AC 589 ms
4,380 KB
testcase_12 AC 585 ms
4,376 KB
testcase_13 AC 1,351 ms
4,376 KB
testcase_14 AC 1,332 ms
4,380 KB
testcase_15 AC 1,332 ms
4,380 KB
testcase_16 AC 1,338 ms
4,376 KB
testcase_17 AC 877 ms
4,380 KB
testcase_18 AC 1,023 ms
4,376 KB
testcase_19 AC 951 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep2(i, x, n) for (int i = x; i <= n; i++)
#define rep3(i, x, n) for (int i = x; i >= n; i--)
#define each(e, v) for (auto &e : v)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) (int)x.size()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int inf = (1 << 30) - 1;
const ll INF = (1LL << 60) - 1;
template <typename T>
bool chmax(T &x, const T &y) {
    return (x < y) ? (x = y, true) : false;
};
template <typename T>
bool chmin(T &x, const T &y) {
    return (x > y) ? (x = y, true) : false;
};

struct io_setup {
    io_setup() {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout << fixed << setprecision(15);
    }
} io_setup;

template <typename T>
T kth_root_int(T a, int k) {
    if (a == 1 || k == 1) return a;
    T L = 0, R = a;
    while (R - L > 1) {
        T M = (L + R) / 2;
        T x = 1;
        bool flag = true;
        for (int i = 0; i < k; i++) {
            if (x > a / M) {
                flag = false;
                break;
            }
            x *= M;
        }
        (flag ? L : R) = M;
    }
    return L;
}

int main() {
    int T;
    cin >> T;

    vector<int> c(60, 0);
    rep2(i, 2, 60) {
        int t = 0, s = 0;
        int memo = i;
        rep2(j, 2, i) {
            int k = 0;
            while (memo % j == 0) {
                memo /= j;
                k++;
            }
            t += k;
            if (k >= 2) s++;
        }
        if (s > 0)
            c[i] = 0;
        else
            c[i] = (t & 1 ? 1 : -1);
    }

    while (T--) {
        ll K;
        cin >> K;
        ll L = 0, R = K * K; // (L,R]
        while (R - L > 1) {
            ll M = (L + R) / 2;
            ll cnt = 1;
            rep2(i, 2, 59) { cnt += (kth_root_int(M, i) - 1) * c[i]; }
            if (cnt >= K)
                R = M;
            else
                L = M;
        }
        cout << R << '\n';
    }
}
0