結果

問題 No.1666 累乗数
ユーザー たたき@競プロたたき@競プロ
提出日時 2023-08-29 01:59:37
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 1,301 ms / 2,000 ms
コード長 1,283 bytes
コンパイル時間 6,435 ms
コンパイル使用メモリ 307,712 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-12-30 20:14:25
合計ジャッジ時間 31,308 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
using mint=modint998244353; //1000000007;
using ll=long long;
using pp=pair<int,int>;
#define sr string 
#define vc vector
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define pb push_back
#define all(v) v.begin(),v.end()
#define pque priority_queue
#define bpc(a) __builtin_popcount(a)
int h=100;
ll mpow(ll a,ll t){
  if(t==0)return 1;
  ll res=mpow(a,t/2);
  if(res==-1)return -1;
  if(res>1e9)return -1;
  res*=res;
  if(t&1){
    if(res>1e18/a)return -1;
    res*=a;
  }
  return res;
}
void sol(){
  vc<int>mv(h,-1),p(h,1);
  for(int i=2;i<h;i++)if(p[i]){
    for(int j=i*i;j<h;j+=i*i)mv[j]=0;
    for(int j=i;j<h;j+=i)mv[j]*=-1,p[j]=0;
  }
  //rep(i,h)cout<<i<<' '<<mv[i]<<"\n";
  ll k;cin>>k;
  ll wa=0,ac=1e18;
  while(ac-wa>1){
    ll x=(ac+wa)/2;
    ll kk=1;
    for(ll i=60;i>=2;i--){
      ll l=1,r=1e9+1;
      while(r-l>1){
        ll m=(r+l)/2;
        ll res=mpow(m,i);
        if(res==-1||res>x)r=m;
        else l=m;
      }
      kk+=(l-1)*mv[i];
    }
    if(kk>=k)ac=x;
    else wa=x;
  }
  
  //for(int i=2;i<=24;i++)if(24%i==0)a+=mv[i];
  //cout<<a<<"\n";
  cout<<ac<<"\n";
  return;
}
int main(){
  int t;cin>>t;
  rep(z,t)sol();
}
0