結果
| 問題 |
No.1666 累乗数
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-09-03 22:04:52 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 920 ms / 2,000 ms |
| コード長 | 1,005 bytes |
| コンパイル時間 | 1,055 ms |
| コンパイル使用メモリ | 78,024 KB |
| 実行使用メモリ | 25,120 KB |
| 最終ジャッジ日時 | 2024-12-15 13:34:40 |
| 合計ジャッジ時間 | 21,073 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 19 |
コンパイルメッセージ
main.cpp:37:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
37 | main()
| ^~~~
ソースコード
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
long sq(long N,long k)
{
if(k>=30)return 1;
long L=0,R=N+1;
while(R-L>1)
{
long mid=(L+R)/2;
long t=1;
bool ok=true;
for(int i=0;i<k;i++)
{
if(t>N/mid)
{
ok=false;
break;
}
t*=mid;
}
if(ok)L=mid;
else R=mid;
}
return L;
}
vector<long>S,Sq;
long cnt(long N)
{
long ans=0;
ans+=upper_bound(Sq.begin(),Sq.end(),N)-Sq.begin();
long now=sq(N,2);
ans+=now;
return ans;
}
main()
{
const long LIM=1e18;
for(long a=2;;a++)
{
bool ch=false;
long t=a*a;
if(t>LIM/a)break;
while(t<=LIM/a)
{
t*=a;
S.push_back(t);
}
}
sort(S.begin(),S.end());
S.erase(unique(S.begin(),S.end()),S.end());
for(long t:S)
{
long now=sq(t,2);
if(now*now!=t)Sq.push_back(t);
}
int T;
//cout<<cnt(4)<<endl;
//return 0;
cin>>T;
for(;T--;)
{
long K;cin>>K;
long L=0,R=1e18;
while(R-L>1)
{
long mid=(L+R)/2;
if(cnt(mid)<K)L=mid;
else R=mid;
}
cout<<R<<endl;
}
}