結果
問題 | No.1664 Unstable f(n) |
ユーザー |
![]() |
提出日時 | 2021-09-03 21:38:37 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 4 ms / 2,000 ms |
コード長 | 1,315 bytes |
コンパイル時間 | 877 ms |
コンパイル使用メモリ | 90,712 KB |
最終ジャッジ日時 | 2025-01-24 05:05:57 |
ジャッジサーバーID (参考情報) |
judge1 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 38 |
ソースコード
#include <iostream>#include <algorithm>#include <iomanip>#include <vector>#include <queue>#include <set>#include <map>#include <cassert>#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }using namespace std;typedef long long ll;const ll INF = 2e18;ll pow(ll x, int n){ll ans = 1;for(int i = 0; i < n; i++){if(INF/x < ans) return INF;ans *= x;}return ans;}ll root_floor(ll n, ll k){if(n == 1) return 1;if(k == 1) return n;ll l = 1, r = n;while(r-l > 1){ll x = (l+r)/2;if(pow(x, k) > n) r = x;else l = x;}return l;}int main(){ios::sync_with_stdio(false);cin.tie(0);cout << setprecision(10) << fixed;ll n; cin >> n;ll ans = n;int x = 1;while(true){ll r = root_floor(n, x);ll p = pow(r, x);ll i = r, j = x, k = n-p;chmin(ans, i+j+k);if(r == 1) break;x++;}cout << ans << endl;}