結果

問題 No.1664 Unstable f(n)
ユーザー umezo
提出日時 2021-09-03 23:01:56
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 929 ms / 2,000 ms
コード長 749 bytes
コンパイル時間 6,447 ms
コンパイル使用メモリ 467,500 KB
最終ジャッジ日時 2025-01-24 06:51:49
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 38
権限があれば一括ダウンロードができます

ソースコード

diff #

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
 
#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;

Bint modpow(Bint x,Bint n){
  Bint ans=1;
  while(n){
    if(n&1) ans=ans*x;
    x=x*x;
    n/=2;
  }
  return ans;
}
 
int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  
  Bint n;
  cin>>n;
  
  Bint ans=n;
  for(Bint i=2;i<=min(n,(Bint)1000000);i++){
    Bint j=0;
    while(modpow(i,j+1)<=n) j++;
    ans=min(ans,i+j+n-modpow(i,j));
  }
  
  Bint m=sqrt(n);
  ans=min(ans,m+2+n-m*m);
  cout<<ans<<endl;
  
  return 0;
}
0