結果
| 問題 | No.1666 累乗数 |
| コンテスト | |
| ユーザー |
tko919
|
| 提出日時 | 2021-09-04 00:20:57 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 122 ms / 2,000 ms |
| コード長 | 1,313 bytes |
| 記録 | |
| コンパイル時間 | 2,106 ms |
| コンパイル使用メモリ | 199,788 KB |
| 最終ジャッジ日時 | 2025-01-24 07:27:35 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 19 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:46:13: warning: ‘add’ may be used uninitialized [-Wmaybe-uninitialized]
46 | cnt+=add;
| ~~~^~~~~
main.cpp:44:27: note: ‘add’ was declared here
44 | ll sub=sqrt(mid),add;
| ^~~
ソースコード
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
//template
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define ALL(v) (v).begin(),(v).end()
using ll=long long int;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
template<typename T>inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T>inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const ll LIM=1000000000000000000LL;
int main(){
vector<ll> other;
for(ll a=2;a<=1000001;a++){
ll add=a*a;
rep(_,0,65){
if(add>=LIM/a)break;
add*=a;
{
ll sq=sqrt(add);
rep(off,-5,5)if(ll(sq+off)*(sq+off)==add)goto fail;
other.push_back(add);
fail:;
}
}
}
sort(ALL(other));
other.erase(unique(ALL(other)),other.end());
int q;
cin>>q;
while (q--)
{
int x;
cin>>x;
x--;
ll lb=0,rb=LIM+5;
while(rb-lb>1){
ll mid=(lb+rb)>>1;
ll cnt=upper_bound(ALL(other),mid)-other.begin();
ll sub=sqrt(mid),add;
rep(off,-5,5)if(ll(sub+off)*(sub+off)<=mid)add=sub+off;
cnt+=add;
if(cnt>x)rb=mid;
else lb=mid;
}
cout<<rb<<'\n';
}
return 0;
}
tko919