結果

問題 No.1666 累乗数
ユーザー otoshigo
提出日時 2021-09-14 06:12:40
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,493 bytes
コンパイル時間 2,497 ms
コンパイル使用メモリ 194,324 KB
最終ジャッジ日時 2025-01-24 13:52:24
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 4 WA * 15
権限があれば一括ダウンロードができます

ソースコード

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 cnt_i(ll x,int i){
    ll y = floor(pow(x,1/double(i)));
    rrep(j,y+2,y-2){
        if (pow(j,i) < 0) cout << "HUHUHU" << endl;
        if (pow(j,i) <= x) {
            return j;
        }
    }
    return 0;
}

bool f(ll x,ll k){ //x以下の累乗数の個数がk個以下か
    ll ju = 0;
    vl cnt(61);
    rrep(i,60,1){
        // ju += (x以下のi乗数の個数)
        ll c = cnt_i(x,i);
        for (int j = 2*i; j <= 60; j += i){
            c -= cnt[j];
        }
        cnt[i] = c;
        ju += c;
    }
    //cout << ju << " " << k << endl;
    if (ju <= k) return true;
    else return false;
}

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

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