結果

問題 No.1664 Unstable f(n)
ユーザー shiroha_F14
提出日時 2021-07-27 20:43:54
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 549 bytes
コンパイル時間 1,745 ms
コンパイル使用メモリ 167,096 KB
実行使用メモリ 13,640 KB
最終ジャッジ日時 2024-12-15 08:46:43
合計ジャッジ時間 33,027 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 25 WA * 4 TLE * 9
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

using ll = long long;

ll modpow(ll x, ll n, int mod){
  ll ret = 1;
  if(mod == 0){
    while(n > 0){
      if(n & 1) ret *= x;
      x *= x;
      n >>= 1;
    }
  }else{
    while(n > 0){
      if(n & 1) ret = ret * x % mod;
      x = x * x % mod;
      n >>= 1;
    }
  }
  return ret;
}

int main(){
  ll x; cin >> x;
  ll ans = LLONG_MAX;
  for(ll i = 2LL; i <= sqrt(x); i++){
    ll j = log(x) / log(i);
    ll k = x - modpow(i, j, 0);
    ans = min(ans, i + j + k);
  }
  cout << ans << endl;
}
0