結果
| 問題 | 
                            No.1664 Unstable f(n)
                             | 
                    
| コンテスト | |
| ユーザー | 
                             umezo
                         | 
                    
| 提出日時 | 2021-09-03 22:54:09 | 
| 言語 | C++17  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 550 bytes | 
| コンパイル時間 | 2,000 ms | 
| コンパイル使用メモリ | 193,788 KB | 
| 最終ジャッジ日時 | 2025-01-24 06:42:47 | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge5 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 37 WA * 1 | 
ソースコード
#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;
ll modpow(ll x,ll n){
  ll 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);
  
  ll n;
  cin>>n;
  
  ll ans=n;
  for(int i=2;i<=min(n,1000000LL);i++){
    ll j=log(n)/(log(i));
    ans=min(ans,i+j+n-modpow(i,j));
  }
  
  ll m=sqrt(n);
  ans=min(ans,m+2+n-m*m);
  cout<<ans<<endl;
  
  return 0;
}
            
            
            
        
            
umezo