結果
| 問題 |
No.1664 Unstable f(n)
|
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 2025-03-20 19:03:22 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 51 ms / 2,000 ms |
| コード長 | 730 bytes |
| コンパイル時間 | 169 ms |
| コンパイル使用メモリ | 82,160 KB |
| 実行使用メモリ | 65,996 KB |
| 最終ジャッジ日時 | 2025-03-20 19:04:19 |
| 合計ジャッジ時間 | 3,597 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 38 |
ソースコード
n = int(input())
def is_power_exceeding(i, j, n):
result = 1
for _ in range(j):
result *= i
if result > n:
return True
return False
min_sum = n # Initialize with j=0 case
max_j = 60 # Since log2(1e18) is about 60
for j in range(2, max_j + 1):
low = 1
high = n
best_i = 1
while low <= high:
mid = (low + high) // 2
if is_power_exceeding(mid, j, n):
high = mid - 1
else:
best_i = mid
low = mid + 1
# Calculate best_i^j
power = 1
for _ in range(j):
power *= best_i
k = n - power
current_sum = best_i + j + k
if current_sum < min_sum:
min_sum = current_sum
print(min_sum)
lam6er