結果
| 問題 | No.1664 Unstable f(n) | 
| コンテスト | |
| ユーザー |  monnu | 
| 提出日時 | 2021-09-03 22:49:28 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 15 ms / 2,000 ms | 
| コード長 | 627 bytes | 
| コンパイル時間 | 3,157 ms | 
| コンパイル使用メモリ | 229,980 KB | 
| 実行使用メモリ | 6,820 KB | 
| 最終ジャッジ日時 | 2024-12-15 16:06:26 | 
| 合計ジャッジ時間 | 4,561 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 38 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
using ll=long long;
using Graph=vector<vector<pair<int,int>>>;
#define MAX 100000
#define MOD 1000000007
#define INF 1000000000000000000
int main(){
  ll n;
  cin>>n;
  ll ans=n;
  for(ll i=2;i<=1000000;i++){
    ll x=1;
    int j=0;
    while(x<=n/i){
      x*=i;
      j++;
      ans=min<ll>(ans,i+(ll)j+n-x);
    }
  }
  ll left=0;
  ll right=1000000001;
  while(left+1<right){
    ll x=(left+right)/2;
    if(x*x<=n){
      left=x;
    }else{
      right=x;
    }
  }
  ans=min<ll>(ans,left+2+n-left*left);
  cout<<ans<<'\n';
}
            
            
            
        