結果

問題 No.1664 Unstable f(n)
ユーザー umezoumezo
提出日時 2021-09-03 23:01:56
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 869 ms / 2,000 ms
コード長 749 bytes
コンパイル時間 10,893 ms
コンパイル使用メモリ 456,644 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-05-09 06:28:40
合計ジャッジ時間 24,164 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 387 ms
5,248 KB
testcase_02 AC 165 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 598 ms
5,376 KB
testcase_12 AC 808 ms
5,376 KB
testcase_13 AC 788 ms
5,376 KB
testcase_14 AC 753 ms
5,376 KB
testcase_15 AC 633 ms
5,376 KB
testcase_16 AC 725 ms
5,376 KB
testcase_17 AC 831 ms
5,376 KB
testcase_18 AC 843 ms
5,376 KB
testcase_19 AC 869 ms
5,376 KB
testcase_20 AC 751 ms
5,376 KB
testcase_21 AC 357 ms
5,376 KB
testcase_22 AC 356 ms
5,376 KB
testcase_23 AC 357 ms
5,376 KB
testcase_24 AC 353 ms
5,376 KB
testcase_25 AC 359 ms
5,376 KB
testcase_26 AC 14 ms
5,376 KB
testcase_27 AC 13 ms
5,376 KB
testcase_28 AC 36 ms
5,376 KB
testcase_29 AC 5 ms
5,376 KB
testcase_30 AC 20 ms
5,376 KB
testcase_31 AC 354 ms
5,376 KB
testcase_32 AC 591 ms
5,376 KB
testcase_33 AC 370 ms
5,376 KB
testcase_34 AC 357 ms
5,376 KB
testcase_35 AC 753 ms
5,376 KB
testcase_36 AC 360 ms
5,376 KB
testcase_37 AC 617 ms
5,376 KB
testcase_38 AC 4 ms
5,376 KB
testcase_39 AC 534 ms
5,376 KB
testcase_40 AC 595 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

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