結果

問題 No.1664 Unstable f(n)
ユーザー shiroha_F14
提出日時 2021-09-04 14:55:36
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 630 bytes
コンパイル時間 1,992 ms
コンパイル使用メモリ 167,716 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-12-18 01:25:25
合計ジャッジ時間 2,561 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 3
other AC * 3 WA * 35
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using ll = long long;

// better precision power
ll mpow(ll x, ll y){
  ll ret = 1;
  while(y > 0){
    if(y & 1) ret *= x;
    x *= x;
    y >>= 1;
  }
  return ret;
}

int main(){
  ll n; cin >> n;
  if(n < 4LL){
    cout << n << endl;
  }else{
    ll ans = LLONG_MAX;
    for(ll j = 2; j <= log2(n); j++){
      ll i = pow(n, 1.0 / j);
      // fix error of i
      while(pow(i + 1, j) > n) i--;
      while(pow(i + 1, j) <= n) i++;
      ll k = n - mpow(i, j);
      ans = min(ans, i + j + k);
      cout << i << " " << j << " " << k << endl;
    }
    cout << ans << endl;
  }
}
0