牛客原题:https://www.nowcoder.com/practice/caf35ae421194a1090c22fe223357dca?tpId=37&tqId=21330&rp=1&ru=/exam/oj/ta&qru=/exam/oj/ta&sourceUrl=%2Fexam%2Foj%2Fta%3FtpId%3D37&difficulty=undefined&judgeStatus=undefined&tags=&title=
关键点:利用牛顿迭代公式~
const rl = require("readline").createInterface({ input: process.stdin });
var iter = rl[Symbol.asyncIterator]();
const readline = async () => (await iter.next()).value;void (async function () {// Write your code here// x^3 = a ,即 fx = x^3 -a// 牛顿迭代公式 下一次近似解 xn+1 = xn- f(x)/f'(x)while ((line = await readline())) {let tokens = line.split(" ");const a = parseFloat(tokens[0]);let x = a / 3; // 设定一个初始x值const tolerance = 1e-6; // 设置一个精度while (Math.abs(a - x * x * x) > tolerance) {const fx = x * x * x - a;x = x - fx / (3 * x * x);}console.log(parseFloat(x.toFixed(1)))}
})();