結果
| 問題 | No.1664 Unstable f(n) |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-09-18 18:30:35 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 6 ms / 2,000 ms |
| コード長 | 951 bytes |
| 記録 | |
| コンパイル時間 | 6,358 ms |
| コンパイル使用メモリ | 415,520 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-06-30 16:18:18 |
| 合計ジャッジ時間 | 7,662 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 38 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部が10進数で1024桁の浮動小数点数型(TLEしたら小さくする)
using Real = mp::number<mp::cpp_dec_float<1024>>;
Bint mypow(Bint x,Bint n){
Bint res=1;
while(n>0){
if(n&1){
res=res*x;
}
x=x*x;
n>>=1;
}
return res;
}
int main(){
Bint N;
cin>>N;
Bint ans=N;
Bint j=2;
while(mypow(2,j)<=N){
Bint left=0,right=N+10;
while(right-left>1){
Bint mid=left+(right-left)/2;
if(mypow(mid,j)>N){
right=mid;
}else{
left=mid;
}
}
ans=min(ans,left+j+N-mypow(left,j));
j++;
}
cout<<ans<<endl;
return 0;
}