結果

問題 No.1666 累乗数
ユーザー monnumonnu
提出日時 2021-09-04 19:45:32
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 982 ms / 2,000 ms
コード長 1,908 bytes
コンパイル時間 5,714 ms
コンパイル使用メモリ 228,940 KB
実行使用メモリ 73,800 KB
最終ジャッジ日時 2023-08-23 10:51:10
合計ジャッジ時間 23,920 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
73,512 KB
testcase_01 AC 977 ms
73,800 KB
testcase_02 AC 974 ms
73,564 KB
testcase_03 AC 972 ms
73,628 KB
testcase_04 AC 967 ms
73,500 KB
testcase_05 AC 978 ms
73,632 KB
testcase_06 AC 974 ms
73,572 KB
testcase_07 AC 980 ms
73,728 KB
testcase_08 AC 975 ms
73,436 KB
testcase_09 AC 978 ms
73,584 KB
testcase_10 AC 968 ms
73,624 KB
testcase_11 AC 975 ms
73,552 KB
testcase_12 AC 973 ms
73,504 KB
testcase_13 AC 975 ms
73,572 KB
testcase_14 AC 979 ms
73,520 KB
testcase_15 AC 979 ms
73,536 KB
testcase_16 AC 978 ms
73,584 KB
testcase_17 AC 977 ms
73,680 KB
testcase_18 AC 979 ms
73,552 KB
testcase_19 AC 982 ms
73,560 KB
権限があれば一括ダウンロードができます

ソースコード

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 60
#define MOD 1000000007
#define INF 1000000000000000000

vector<int> p;
vector<bool> p_table(MAX+1,true);
void prime(){
  p_table.at(0)=false,p_table.at(1)=false;
  for(int i=2;i<=MAX;i++){
    if(p_table.at(i)){
      p.push_back(i);
      for(int j=2;i*j<=MAX;j++){
        p_table.at(i*j)=false;
      }
    }
  }
}
int M=1000000;
vector<int> is_perfect_power(M+1,0);
vector<vector<int>> sum;

int N;

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 i=0;i<N;i++){
    int b=p[i];
    ll left=0;
    ll right=1000000001;
    while(left+1<right){
      ll c=(left+right)/2;
      if(log10(c)*(double)b>=100){
        right=c;
        continue;
      }
      if(pow((ll)c,b)>=2e18){
        right=c;
        continue;
      }
      if(my_pow(c,b)<=x){
        left=c;
      }else{
        right=c;
      }
    }
    if(i>0){
      ans+=left-sum[i-1][left];
    }else{
      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;
  prime();
  N=p.size();

  is_perfect_power[1]=1;
  sum.resize(N);
  for(int i=0;i<N;i++){
    sum[i].resize(M+1,0);
  }
  for(int i=0;i<N;i++){
    for(int j=2;pow(j,p[i])<=2e18&&my_pow(j,p[i])<=M;j++){
      is_perfect_power[my_pow(j,p[i])]=1;
    }
    for(int j=1;j<=M;j++){
      sum[i][j]=sum[i][j-1]+is_perfect_power[j];
    }
  }

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