結果

問題 No.1666 累乗数
ユーザー monnumonnu
提出日時 2021-09-04 15:13:47
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,181 bytes
コンパイル時間 3,737 ms
コンパイル使用メモリ 226,904 KB
実行使用メモリ 8,768 KB
最終ジャッジ日時 2023-08-22 23:13:33
合計ジャッジ時間 7,445 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
8,088 KB
testcase_01 TLE -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
using ll=long long;
using Graph=vector<vector<pair<int,int>>>;
#define MAX 100000
#define MOD 1000000007
#define INF 1000000000000000000

ll my_pow(ll x,int n){
  ll ret=1;
  while(n>0){
    if((n&1)==1){
      ret=ret*x;
    }
    n>>=1;
    x=x*x;
  }
  return ret;
}

//x以下の累乗数の個数
ll counting(ll x){
  if(x==0){
    return 0;
  }
  ll ans=1;
  for(int b=2;b<=60;b++){
    ll left=0;
    ll right=1000000001;
    while(left+1<right){
      ll c=(left+right)/2;
      if(pow((ll)c,b)>=2e18){
        right=c;
        continue;
      }
      if(my_pow(c,b)<=x){
        left=c;
      }else{
        right=c;
      }
    }
    int cnt=0;
    for(int i=2;i<=b;i++){
      if(b%i==0){
        cnt++;
      }
    }
    if(cnt==1){
      ans+=left-1;
    }
  }
  return ans;
}

void solve(){
  ll K;
  cin>>K;
  ll left=0;
  ll right=1000000000000000001;
  while(left+1<right){
    ll c=(left+right)/2;
    if(counting(c)<K){
      left=c;
    }else{
      right=c;
    }
  }
  cout<<right<<'\n';
}

int main(){
  int T;
  cin>>T;
  for(int i=0;i<T;i++){
    solve();
  }
}
0