結果

問題 No.1664 Unstable f(n)
ユーザー ManjushriMitra
提出日時 2024-12-30 18:33:27
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 1,276 bytes
コンパイル時間 3,462 ms
コンパイル使用メモリ 243,864 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-12-30 18:33:33
合計ジャッジ時間 4,759 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 38
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,m,n) for(int i=m; i<int(n); ++i)
#define repll(i,m,n) for(ll i=m; i<ll(n); ++i)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define fi first
#define se second

template<typename T> bool chmin(T& a, T b){ if(a > b){a = b; return true;} return false; }
template<typename T> bool chmax(T& a, T b){ if(a < b){a = b; return true;} return false; }

template<typename T> T gcd(T a, T b){ return a % b ? gcd(b, a % b) : b; }
template<typename T> T lcm(T a, T b){ return a / gcd(a, b) * b; }

ll n;

ll power(ll x, ll y){
    ll res = 1LL;
    rep(i, 0, y){
        if(double(res * x) > double(n)) return -1LL;
        res *= x;
    }
    return res;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    cin >> n;
    ll ans = n; // (i, j, k) = (1, 0, n-1)

    for(ll j = 2LL; (1LL << j) <= n; ++j){
        ll lo = 0LL, hi = ll(1e9 + 100), mid;
        while(abs(lo - hi) > 1LL){
            mid = (lo + hi) / 2LL;
            if(power(mid, j) == -1 || power(mid, j) > n) hi = mid;
            else lo = mid;
        }
        ll k = n - power(lo, j);
        if(k >= 0LL) chmin(ans, lo + j + k); 
    }
    cout << ans << endl;

    return 0;
}
0