結果

問題 No.1664 Unstable f(n)
ユーザー tnakao0123tnakao0123
提出日時 2021-09-04 15:15:29
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 36 ms / 2,000 ms
コード長 1,151 bytes
コンパイル時間 1,067 ms
コンパイル使用メモリ 89,752 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-22 23:15:22
合計ジャッジ時間 3,014 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 4 ms
4,380 KB
testcase_12 AC 28 ms
4,376 KB
testcase_13 AC 25 ms
4,380 KB
testcase_14 AC 22 ms
4,380 KB
testcase_15 AC 8 ms
4,380 KB
testcase_16 AC 18 ms
4,376 KB
testcase_17 AC 31 ms
4,376 KB
testcase_18 AC 34 ms
4,376 KB
testcase_19 AC 36 ms
4,380 KB
testcase_20 AC 23 ms
4,380 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 2 ms
4,380 KB
testcase_34 AC 2 ms
4,380 KB
testcase_35 AC 22 ms
4,376 KB
testcase_36 AC 2 ms
4,376 KB
testcase_37 AC 6 ms
4,380 KB
testcase_38 AC 2 ms
4,376 KB
testcase_39 AC 2 ms
4,376 KB
testcase_40 AC 4 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 1664.cc:  No.1664 Unstable f(n) - yukicoder
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const long long LINF = 1LL << 62;

/* typedef */

typedef long long ll;

/* global variables */

/* subroutines */

/* main */

int main() {
  ll n;
  scanf("%lld", &n);

  if (n == 1) puts("1");
  else {
    ll minsum = n; // j = 0 -> 1 + k = n

    for (int i = 2;; i++) {
      int j = 0;
      ll p = 1;
      for (ll m = n; m >= i; j++, m /= i, p *= i);
      ll sum = i + j + (n - p);
      minsum = min(minsum, sum);
      if (j <= 2) break;
    }

    int i0 = 1, i1 = 1000000000 + 1;;
    while (i0 + 1 < i1) {
      int i = (i0 + i1) / 2;
      if ((ll)i * i <= n) i0 = i;
      else i1 = i;
    }
    ll k = n - (ll)i0 * i0;
    minsum = min(minsum, i0 + 2 + k);

    printf("%lld\n", minsum);
  }
  return 0;
}
0