結果

問題 No.1666 累乗数
ユーザー nakaken88nakaken88
提出日時 2021-09-04 09:09:34
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 376 ms / 2,000 ms
コード長 1,300 bytes
コンパイル時間 1,656 ms
コンパイル使用メモリ 173,024 KB
実行使用メモリ 60,064 KB
最終ジャッジ日時 2023-08-22 15:43:29
合計ジャッジ時間 10,157 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 369 ms
58,872 KB
testcase_01 AC 368 ms
58,484 KB
testcase_02 AC 371 ms
59,372 KB
testcase_03 AC 367 ms
59,868 KB
testcase_04 AC 370 ms
60,064 KB
testcase_05 AC 372 ms
58,796 KB
testcase_06 AC 371 ms
59,112 KB
testcase_07 AC 369 ms
59,384 KB
testcase_08 AC 366 ms
58,912 KB
testcase_09 AC 368 ms
58,488 KB
testcase_10 AC 373 ms
59,292 KB
testcase_11 AC 376 ms
59,252 KB
testcase_12 AC 376 ms
58,492 KB
testcase_13 AC 371 ms
58,856 KB
testcase_14 AC 371 ms
58,776 KB
testcase_15 AC 373 ms
58,900 KB
testcase_16 AC 370 ms
58,420 KB
testcase_17 AC 371 ms
59,048 KB
testcase_18 AC 373 ms
59,192 KB
testcase_19 AC 370 ms
58,608 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

#ifdef LOCAL
#include "debug.hpp"
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

ll K;
set<ll> st;
vector<ll> v;

void calc_init() {
  for (ll i = 3; i < 65; i++) {
    for (ll j = 2; j <= 1e6; j++) {
      ll x = 1;
      for (ll k = 0; k < i; k++) {
        if (x >= 2e18 / j) {
          x = 2e18;
          break;
        }
        x *= j;
      }
      if (x > 1e18) break;

      ll sq = sqrt(x);
      if ((sq + 1) * (sq + 1) <= x) sq++;
      if (sq * sq > x) sq--;

      if (sq * sq != x) {
        st.insert(x);
      }
    }
  }
  for (auto x: st) v.push_back(x);
}

bool isOK(ll key) {
  ll max = sqrt(key);
  if ((max + 1) * (max + 1) <= key) max++;
  if (max * max > key) max--;

  ll l = upper_bound(v.begin(), v.end(), key) - v.begin();
  ll cnt = max + l;
  return (cnt >= K);
}


int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  calc_init();
  ll T; cin >> T;
  for (ll t = 0; t < T; t++) {
    cin >> K;

    // N以下の累乗数はK個以上?
    ll ok = 2e18, ng = 0;
    while (abs(ok - ng) > 1) {
      ll mid = (ok + ng) / 2;
      if (isOK(mid)) ok = mid;
      else ng = mid;
    }
    cout << ok << '\n';
  }
  return 0;
}
0