結果

問題 No.1664 Unstable f(n)
ユーザー 杨娵隅杨娵隅
提出日時 2021-09-03 22:08:09
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 645 bytes
コンパイル時間 1,678 ms
コンパイル使用メモリ 166,100 KB
実行使用メモリ 10,624 KB
最終ジャッジ日時 2024-05-09 04:14:36
合計ジャッジ時間 5,432 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
10,624 KB
testcase_01 AC 3 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 TLE -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:3:18: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+18' to '2147483647' [-Woverflow]
    3 | const int maxn = 1e18;
      |                  ^~~~

ソースコード

diff #

#include <bits/stdc++.h>
typedef long long ll;
const int maxn = 1e18;

ll qmi(ll a, ll k)
{
  ll res = 1;
  while (k)
  {
    if (k & 1) res = (ll)res * a;
    k >>= 1; a = (ll)a * a;
  }return res;
}
ll a, b, k = 1e18;
int main()
{
  ll n; scanf("%lld", &n);
  if (n == 1) {printf("1\n"); return 0;}
  if (n == 2) {printf("3\n"); return 0;}
  if (n == 3) {printf("4\n"); return 0;}
  for (ll i = 2; i * i <= n; i ++)
  {
    for (ll j = 0; qmi(i, j) <= n; j ++)
    {
      if (k > (n - qmi(i, j)))
      {
        a = i;
        b = j;
        k = std::min(k, (n - qmi(i, j)));
      }
    }
  }std::cout << a + b + k << "\n";
  
  return 0;
}
0