結果

問題 No.1666 累乗数
ユーザー re_re0101re_re0101
提出日時 2021-09-02 06:11:57
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 811 ms / 2,000 ms
コード長 1,047 bytes
コンパイル時間 4,501 ms
コンパイル使用メモリ 175,564 KB
実行使用メモリ 113,592 KB
最終ジャッジ日時 2023-08-21 19:06:02
合計ジャッジ時間 20,188 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 756 ms
113,464 KB
testcase_01 AC 798 ms
113,488 KB
testcase_02 AC 766 ms
113,440 KB
testcase_03 AC 782 ms
113,440 KB
testcase_04 AC 796 ms
113,464 KB
testcase_05 AC 800 ms
113,592 KB
testcase_06 AC 794 ms
113,460 KB
testcase_07 AC 772 ms
113,544 KB
testcase_08 AC 788 ms
113,492 KB
testcase_09 AC 771 ms
113,528 KB
testcase_10 AC 792 ms
113,484 KB
testcase_11 AC 787 ms
113,528 KB
testcase_12 AC 788 ms
113,452 KB
testcase_13 AC 777 ms
113,536 KB
testcase_14 AC 803 ms
113,440 KB
testcase_15 AC 811 ms
113,452 KB
testcase_16 AC 783 ms
113,536 KB
testcase_17 AC 795 ms
113,536 KB
testcase_18 AC 781 ms
113,528 KB
testcase_19 AC 783 ms
113,544 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

ll exp(ll n,ll r){if(r==0)return 1;return n*exp(n,r-1);}


int main(){
    set<ll>st;
    set<ll>unuse;
    for(ll i=1;i<=1000;i++)unuse.insert(i*i);
    for(ll i=2;i<=((ll)1e6)+10;i++){
        if(unuse.count(i))continue;
        for(ll j=3;;j+=2){
            if(pow(i,j)<=((ll)1e18)+10)st.insert(exp(i,j));
            else break;
        }
    }
    map<ll,ll>mp;
    ll cur=0;
    for(auto x:st){
        mp[x]=++cur;
    }
    ll ma=*rbegin(st);

    auto cnt=[&](ll n)->ll{
        ll ok=0;
        ll ng=((ll)1e9)+10;
        while(ng-ok>1){
            ll mid=(ok+ng)/2;
            if(mid*mid<=n)ok=mid;
            else ng=mid;
        }
        if(n>=ma)return st.size()+ok;
        else return mp[(*st.lower_bound(n+1))]-1+ok;
    };

    ll t;cin>>t;
    while(t--){
        ll m;cin>>m;
        ll ok=1e18,ng=-1;
        while(ok-ng>1){
            ll mid=(ok+ng)/2;
            if(cnt(mid)>=m)ok=mid;
            else ng=mid;
    }
        cout<<ok<<endl;
    }
}
0