結果

問題 No.1664 Unstable f(n)
ユーザー a01sa01to
提出日時 2025-05-20 00:22:54
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 997 bytes
コンパイル時間 3,619 ms
コンパイル使用メモリ 275,656 KB
実行使用メモリ 7,844 KB
最終ジャッジ日時 2025-05-20 00:23:00
合計ジャッジ時間 4,020 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 38
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
  #include "settings/debug.cpp"
#else
  #define Debug(...) void(0)
#endif
#define rep(i, n) for (int i = 0; i < (n); ++i)
using ll = long long;
using ull = unsigned long long;

constexpr ll INF = LLONG_MAX;

inline ll saturating_pow(ll a, ll b) {
  ll res = 1;
  rep(_, b) {
    if (res > INF / a) return INF;
    res *= a;
  }
  return res;
}

inline ll floor_root(ll n, ll k) {
  ll about = min((long double) INF, powl(n, 1.0l / k));
  while (about > 1 && saturating_pow(about, k) > n) --about;
  while (saturating_pow(about + 1, k) <= n) ++about;
  return about;
}

int main() {
  cin.tie(nullptr)->sync_with_stdio(false);
  ll n;
  cin >> n;
  if (n <= 3) {
    cout << n << '\n';
    return 0;
  }
  ll ans = n + 1;
  for (int j = 2; j <= 60; ++j) {
    ll i = floor_root(n, j);
    ll k = n - saturating_pow(i, j);
    if (k < 0) continue;
    Debug(i, j, k);
    ans = min(ans, i + j + k);
  }
  cout << ans << '\n';
  return 0;
}
0