結果
| 問題 |
No.1664 Unstable f(n)
|
| コンテスト | |
| ユーザー |
shiroha_F14
|
| 提出日時 | 2021-09-04 14:55:49 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 581 bytes |
| コンパイル時間 | 1,833 ms |
| コンパイル使用メモリ | 166,928 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-12-18 01:25:41 |
| 合計ジャッジ時間 | 2,676 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 38 |
ソースコード
#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 << ans << endl;
}
}
shiroha_F14