結果

問題 No.1666 累乗数
ユーザー abc3abc3
提出日時 2021-09-04 06:20:07
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 82 ms / 2,000 ms
コード長 1,895 bytes
コンパイル時間 2,987 ms
コンパイル使用メモリ 207,116 KB
実行使用メモリ 21,164 KB
最終ジャッジ日時 2023-08-22 12:11:31
合計ジャッジ時間 5,756 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
21,164 KB
testcase_01 AC 79 ms
20,200 KB
testcase_02 AC 79 ms
20,012 KB
testcase_03 AC 79 ms
19,428 KB
testcase_04 AC 79 ms
20,260 KB
testcase_05 AC 79 ms
19,940 KB
testcase_06 AC 78 ms
20,096 KB
testcase_07 AC 80 ms
20,220 KB
testcase_08 AC 78 ms
19,940 KB
testcase_09 AC 80 ms
19,700 KB
testcase_10 AC 80 ms
19,748 KB
testcase_11 AC 81 ms
20,724 KB
testcase_12 AC 80 ms
20,040 KB
testcase_13 AC 80 ms
20,080 KB
testcase_14 AC 79 ms
19,884 KB
testcase_15 AC 81 ms
20,988 KB
testcase_16 AC 81 ms
19,652 KB
testcase_17 AC 81 ms
20,284 KB
testcase_18 AC 82 ms
20,832 KB
testcase_19 AC 80 ms
19,628 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

    #include <bits/stdc++.h>
    using namespace std;
    #include <math.h>
    #include <iomanip>
    #include <cstdint>
    #include <string>
    #include <sstream>
    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; }
    #define rep(i,n) for (int i = 0; i < (n); ++i)
    typedef long long ll;
    typedef long double ld;
    using P=pair<ll,ll>;
    const ld INF=1e18;
    const int mod=1e9+7;
    
    ll f(ll a,ll b){
        ll res=1;
        rep(i,b){
           res*=a;
        }
        return res;
    }

    void solve(){
        vector<ll>s(1000001);
        rep(i,1001){
            s[i*i]=1;
        }
        vector<ll>t;
        for(int i=3;i<=60;i+=2){
            ll j=1;
            ll lim=pow(1e18+10000,1.0/i);
            while(j<=lim){
                if(!s[j]){t.push_back(f(j,i));}
                j++;
            }
        }
        sort(t.begin(),t.end());
        t.erase(unique(t.begin(),t.end()),t.end());

        auto calc=[&](ll n){
            ll l=0,r=1e9+5;
            while(r-l>1){
                ll mid=(l+r)/2;
                if(mid*mid<=n){
                    l=mid;
                }
                else{
                    r=mid;
                }
            }
            ll add=upper_bound(t.begin(),t.end(),n)-t.begin();
            return l+add;
        };

        int T;
        cin>>T;
        rep(i,T){
            ll k;
            cin>>k;
            ll l=0,r=1e18;
            while(r-l>1){
                ll mid=(l+r)/2;
                if(calc(mid)>=k){r=mid;}
                else{l=mid;}
            }
            cout<<r<<endl;
        }
    }  

    int main(){
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        
        solve();
        
        return 0;
    }
0