結果
| 問題 |
No.1664 Unstable f(n)
|
| コンテスト | |
| ユーザー |
ManjushriMitra
|
| 提出日時 | 2024-12-30 18:28:16 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,317 bytes |
| コンパイル時間 | 3,876 ms |
| コンパイル使用メモリ | 243,868 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-12-30 18:28:21 |
| 合計ジャッジ時間 | 5,478 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 37 WA * 1 |
ソースコード
#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);
// cout << lo << ' ' << j << ' ' << k << endl;
chmin(ans, lo + j + k);
}
cout << ans << endl;
return 0;
}
ManjushriMitra