結果

問題 No.1666 累乗数
ユーザー monnumonnu
提出日時 2021-09-04 19:32:14
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,794 bytes
コンパイル時間 3,890 ms
コンパイル使用メモリ 227,392 KB
実行使用メモリ 11,040 KB
最終ジャッジ日時 2023-08-23 10:29:00
合計ジャッジ時間 23,024 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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<int> sum(M+1,0);

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(b!=2){
      ans+=left-sum[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;
  for(int x=2;x*x<=M;x++){
    int i=x;
    while(i*x<=M){
      i*=x;
      is_perfect_power[i]=1;
    }
  }
  for(int i=1;i<=M;i++){
    sum[i]=is_perfect_power[i]+sum[i-1];
  }
  for(int i=0;i<T;i++){
    solve();
  }
}
0