// @EXPECTED_RESULTS@: ACCEPTED, TIME_LIMIT_EXCEEDED import java.math.BigDecimal import java.math.MathContext /** * Thinking of the solution was trivial, implementing it was hard. Could not have solved it this way without internet. * This is probably not the solution the jury had in mind, but it seems to work. * This approximation might need some tweaking to fit the constraints. It might fail or be to slow on larger cases. */ fun main() { println(System.`in`.bufferedReader().lineSequence().drop(1).first() .split(" ").map { BigDecimal(it) }.map { it.pow(3) }.sumOf { it } .cuberoot()) } var ITER: Int = 1000 val mc = MathContext(20) val THREE = BigDecimal("3", mc) val ONE = BigDecimal("1", mc) fun BigDecimal.cuberoot(): BigDecimal { // Search for the cube root via the Newton-Raphson loop. return (0 until ITER).fold(ONE) { x, _ -> x.subtract( x.pow(3, mc) .subtract(this, mc) .divide(THREE.multiply(x.pow(2, mc), mc), mc), mc ) } }