結果

問題 No.1666 累乗数
ユーザー KudeKude
提出日時 2021-09-03 22:08:38
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 191 ms / 2,000 ms
コード長 2,093 bytes
コンパイル時間 5,076 ms
コンパイル使用メモリ 265,312 KB
実行使用メモリ 11,620 KB
最終ジャッジ日時 2024-05-09 04:15:18
合計ジャッジ時間 9,424 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 186 ms
11,488 KB
testcase_01 AC 189 ms
11,488 KB
testcase_02 AC 189 ms
11,420 KB
testcase_03 AC 188 ms
11,484 KB
testcase_04 AC 186 ms
11,484 KB
testcase_05 AC 185 ms
11,488 KB
testcase_06 AC 184 ms
11,620 KB
testcase_07 AC 185 ms
11,488 KB
testcase_08 AC 184 ms
11,424 KB
testcase_09 AC 188 ms
11,484 KB
testcase_10 AC 187 ms
11,488 KB
testcase_11 AC 191 ms
11,488 KB
testcase_12 AC 188 ms
11,488 KB
testcase_13 AC 187 ms
11,492 KB
testcase_14 AC 188 ms
11,488 KB
testcase_15 AC 185 ms
11,492 KB
testcase_16 AC 188 ms
11,488 KB
testcase_17 AC 188 ms
11,492 KB
testcase_18 AC 186 ms
11,492 KB
testcase_19 AC 185 ms
11,472 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
using namespace atcoder;
#define rep(i,n)for (int i = 0; i < int(n); ++i)
#define rrep(i,n)for (int i = int(n)-1; i >= 0; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
template<class T> void chmax(T& a, const T& b) {a = max(a, b);}
template<class T> void chmin(T& a, const T& b) {a = min(a, b);}
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;

constexpr ll MX = 1000000000'000000000;

bool is_square(ll x) {
    ll l = 1, r = 2;
    while(r * r <= x) l = r, r *= 2;
    while(r - l > 1) {
        ll c = (l + r) / 2;
        if (c * c <= x) l = c;
        else r = c;
    }
    return l * l == x;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    VL d;
    for(int b = 3; b < 60; b++) {
        for(ll a = 2;; a++) {
            long long ab = 1;
            bool ok = true;
            rep(_, b) {
                if (ab > MX / a) {
                    ok = false;
                    break;
                }
                ab *= a;
            }
            if (!ok) break;
            if (!is_square(ab)) d.push_back(ab);
        }
    }
    sort(all(d));
    d.erase(unique(all(d)), d.end());
    // cout << d.size() << endl;
    // return 0;
    // rep(i, 10) cout << d[i] << " ";
    // cout << endl;
    int tt;
    cin >> tt;
    while(tt--) {
        int k;
        cin >> k;
        ll l = 1, r = 1000000001;
        while(r - l > 1) {
            ll c = (l + r) / 2;
            // # of <= c^2
            ll cnt = c + (lower_bound(all(d), c * c) - d.begin());
            if (cnt <= k) l = c;
            else r = c;
        }
        auto it = lower_bound(all(d), l * l);
        ll cnt = l + (it - d.begin());
        int rest = k - cnt;
        // cout << l << ' ' << r << ' ' << rest << ' ' << (it - d.begin()) << endl;
        if (rest == 0) {
            cout << l * l << '\n';
        } else {
            cout << it[rest - 1] << '\n';
        }
    }
}
0