結果

問題 No.1666 累乗数
ユーザー milanis48663220milanis48663220
提出日時 2021-09-03 22:30:02
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 280 ms / 2,000 ms
コード長 2,512 bytes
コンパイル時間 1,365 ms
コンパイル使用メモリ 125,828 KB
実行使用メモリ 61,756 KB
最終ジャッジ日時 2023-08-21 23:14:27
合計ジャッジ時間 8,083 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 272 ms
61,756 KB
testcase_01 AC 277 ms
61,136 KB
testcase_02 AC 277 ms
60,308 KB
testcase_03 AC 274 ms
61,740 KB
testcase_04 AC 271 ms
60,832 KB
testcase_05 AC 274 ms
60,364 KB
testcase_06 AC 274 ms
60,484 KB
testcase_07 AC 272 ms
60,128 KB
testcase_08 AC 270 ms
61,108 KB
testcase_09 AC 275 ms
60,552 KB
testcase_10 AC 271 ms
60,520 KB
testcase_11 AC 270 ms
60,852 KB
testcase_12 AC 274 ms
60,200 KB
testcase_13 AC 277 ms
60,924 KB
testcase_14 AC 276 ms
61,028 KB
testcase_15 AC 279 ms
60,304 KB
testcase_16 AC 280 ms
60,832 KB
testcase_17 AC 274 ms
60,248 KB
testcase_18 AC 278 ms
60,776 KB
testcase_19 AC 273 ms
61,092 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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 = 2e18;

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(ll i = 2; 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 = sqrt(k)+0.5;
    if(sq*sq > k) sq--;
    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;
    }
}
0