結果

問題 No.1666 累乗数
ユーザー monnu
提出日時 2021-09-04 15:26:11
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,452 bytes
コンパイル時間 3,817 ms
コンパイル使用メモリ 230,516 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-12-20 01:36:37
合計ジャッジ時間 13,792 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other WA * 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 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 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;
      }
    }
    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();
  for(int i=0;i<T;i++){
    solve();
  }
}
0