結果

問題 No.1666 累乗数
ユーザー otoshigootoshigo
提出日時 2021-09-14 09:01:40
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 987 ms / 2,000 ms
コード長 1,493 bytes
コンパイル時間 2,065 ms
コンパイル使用メモリ 200,532 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-09 04:23:51
合計ジャッジ時間 21,556 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 21 ms
4,380 KB
testcase_01 AC 960 ms
4,376 KB
testcase_02 AC 960 ms
4,376 KB
testcase_03 AC 962 ms
4,380 KB
testcase_04 AC 963 ms
4,376 KB
testcase_05 AC 982 ms
4,376 KB
testcase_06 AC 987 ms
4,376 KB
testcase_07 AC 986 ms
4,380 KB
testcase_08 AC 984 ms
4,380 KB
testcase_09 AC 965 ms
4,376 KB
testcase_10 AC 967 ms
4,380 KB
testcase_11 AC 967 ms
4,376 KB
testcase_12 AC 968 ms
4,380 KB
testcase_13 AC 982 ms
4,380 KB
testcase_14 AC 981 ms
4,380 KB
testcase_15 AC 981 ms
4,376 KB
testcase_16 AC 982 ms
4,376 KB
testcase_17 AC 971 ms
4,380 KB
testcase_18 AC 975 ms
4,376 KB
testcase_19 AC 972 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;  using vvi = vector<vi>;
using vl = vector<ll>;   using vvl = vector<vl>;
using vb = vector<bool>; using vvb = vector<vb>;
using vpi = vector<pii>; using vvpi = vector<vpi>;
using vpl = vector<pll>; using vvpl = vector<vpl>;
const int inf = 1 << 30;
const ll INF = 1LL << 60;
#define rep(i,m,n) for (int i = m; i < (int)(n); i++)
#define rrep(i,m,n) for (int i = m; i > (int)(n); i--)

ll p(ll x,ll y){
    ll ju = 1;
    rep(i,0,y){
        if (ju > INF/double(x)) return INF;
        ju *= x;
    }
    return ju;
}

ll cnt_i(ll x,int i){
    ll ok = 0,ng = floor(pow(x,1/(long double)(i)))+10;
    while (ng-ok > 1){
        ll mid = (ok+ng)/2;
        if (p(mid,i) <= x) ok = mid;
        else ng = mid;
    }
    return ok-1;
}

bool f(ll x,ll k){
    ll ju = 0;
    vl cnt(61);
    rrep(i,60,1){
        ll c = cnt_i(x,i);
        for (int j = 2*i; j <= 60; j += i){
            c -= cnt[j];
        }
        cnt[i] = c;
        ju += c;
    }
    if (ju >= k-1) return true;
    else return false;
}

void solve(){
    ll k; cin >> k;
    ll ng = 0,ok = 1e18+1;
    while (ok-ng > 1){
        ll mid = (ok+ng)/2;
        if (f(mid,k)) ok = mid;
        else ng = mid;
    }
    cout << ok << endl;
}

int main(){
    int t; cin >> t;
    rep(i,0,t){
        solve();
    }
}
0