結果
問題 | No.1664 Unstable f(n) |
ユーザー |
|
提出日時 | 2021-09-04 00:39:17 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 523 bytes |
コンパイル時間 | 1,253 ms |
コンパイル使用メモリ | 167,908 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-12-15 20:40:32 |
合計ジャッジ時間 | 2,198 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 38 |
コンパイルメッセージ
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; | ^~~~
ソースコード
#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; } int main() { ll n; scanf("%lld", &n); if (n <= 4) {std::cout << n << "\n"; return 0;} ll ans = 1e18; for (ll j = 2; j <= 60; j ++) { ll i = pow(n, 1.0 / j); while (pow(i + 1, j) <= n) i ++; ll k = n - qmi(i, j); ans = std::min(ans, i + j + k); } std::cout << ans << "\n"; return 0; }