結果
| 問題 |
No.1666 累乗数
|
| コンテスト | |
| ユーザー |
milanis48663220
|
| 提出日時 | 2021-09-03 22:27:02 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,494 bytes |
| コンパイル時間 | 2,511 ms |
| コンパイル使用メモリ | 120,044 KB |
| 最終ジャッジ日時 | 2025-01-24 06:16:47 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | TLE * 1 |
| other | TLE * 19 |
ソースコード
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <cmath>
#include <numeric>
#include <functional>
#include <cassert>
#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;
typedef long long ll;
class Eratosthenes{
public:
int m;
vector<bool> is_prime;
vector<int> primes;
Eratosthenes(int m_){
m = m_;
init();
}
private:
void init(){
is_prime.assign(m+1, true);
is_prime[0] = false, is_prime[1] = false;
for(int i = 2; i <= m; i++){
if(is_prime[i]){
primes.push_back(i);
for(int j = 2; i*j <= m; j++) is_prime[i*j] = false;
}
}
}
};
const ll INF = 1e18;
ll pow(ll x, int n){
ll ans = 1;
for(int i = 0; i < n; i++){
if(INF/x < ans) return INF;
ans *= x;
}
return ans;
}
ll root_floor(ll n, ll k){
if(n == 1) return 1;
if(k == 1) return n;
ll l = 1, r = n;
while(r-l > 1){
ll x = (l+r)/2;
if(pow(x, k) > n) r = x;
else l = x;
}
return l;
}
const int N_MAX = 1000000;
bool used[N_MAX+1];
set<ll> st;
vector<ll> v;
void init(){
for(int i = 1; i <= N_MAX; i++){
ll cur = (ll)i*(ll)i*(ll)i;
for(int j = 3; ; j++){
st.insert(cur);
if(cur > INF/i) break;
cur *= i;
}
}
for(ll x: st){
ll sq = sqrt(x)+0.5;
if(sq*sq > x) sq--;
if(sq*sq != x){
v.push_back(x);
}
}
}
ll count(ll k){
ll sq = root_floor(k, 2);
auto p = upper_bound(v.begin(), v.end(), k);
ll ans = sq+(p-v.begin());
return ans;
}
ll solve(ll k){
if(k == 1) return 1;
ll l = 1, r = 1e18;
while(r-l > 1){
ll x = (l+r)/2;
if(count(x) >= k) r = x;
else l = x;
}
return r;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout << setprecision(10) << fixed;
init();
int t; cin >> t;
while(t--) {
ll k; cin >> k; cout << solve(k) << endl;
}
}
milanis48663220