結果
| 問題 |
No.1666 累乗数
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-09-04 09:09:34 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 383 ms / 2,000 ms |
| コード長 | 1,300 bytes |
| コンパイル時間 | 1,756 ms |
| コンパイル使用メモリ | 175,776 KB |
| 実行使用メモリ | 59,908 KB |
| 最終ジャッジ日時 | 2024-12-17 15:24:01 |
| 合計ジャッジ時間 | 10,366 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 19 |
ソースコード
#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;
}