結果

問題 No.1666 累乗数
ユーザー nakaken88nakaken88
提出日時 2021-09-04 08:53:08
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,177 bytes
コンパイル時間 1,336 ms
コンパイル使用メモリ 171,724 KB
実行使用メモリ 58,144 KB
最終ジャッジ日時 2024-05-09 21:01:21
合計ジャッジ時間 6,817 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,003 ms
58,144 KB
testcase_01 TLE -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
権限があれば一括ダウンロードができます

ソースコード

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;

void calc_init() {
  for (ll i = 3; i < 62; i++) {
    for (ll j = 2; j <= 1e6; j++) {
      double t = pow(j, i);
      if (t > 1e18) break;
      ll x = pow(j, i);
      ll sq = sqrt(x);
      if ((sq + 1) * (sq + 1) <= x) sq++;
      if (sq * sq > x) sq--;
      if (sq * sq != x) {
        st.insert(x);
        if (x < 100) debug(x);
      }
    }
  }
  
}

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

  ll l = distance(st.begin(), st.upper_bound(key));
  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