import java.io.PrintWriter import java.util.* import kotlin.math.* fun PrintWriter.solve() { val n = nextLong() var min = n for (j in 0..60) { var l = 1L var r = n + 1 outer@while (r - l > 1) { val mid = (l + r) / 2 var pow = 1L for (_i in 0 until j) { if (pow > n / mid) { r = mid continue@outer } pow *= mid } if (pow > n) { r = mid } else { l = mid } } val i = l val k = n - LongArray(j) { i }.fold(1L, Long::times) min = min(min, i + j + k) } println(min) } fun main() { Thread(null, { val writer = PrintWriter(System.out, false) writer.solve() writer.flush() }, "solve", 1.shl(26)) .apply { setUncaughtExceptionHandler { _, e -> e.printStackTrace(); kotlin.system.exitProcess(1) } } .apply { start() }.join() } // region Scanner private var st = StringTokenizer("") private val br = System.`in`.bufferedReader() fun next(): String { while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine()) return st.nextToken() } fun nextInt() = next().toInt() fun nextLong() = next().toLong() fun nextLine() = br.readLine() fun nextDouble() = next().toDouble() // endregion