题解 | #将真分数分解为埃及分数#
将真分数分解为埃及分数
https://www.nowcoder.com/practice/e0480b2c6aa24bfba0935ffcca3ccb7b
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 while ((line = await readline())) { let rest = line; let [a, b] = line.split("/"); let source=b/a let res = []; while (true) { let [a, b] = rest.split("/"); let sub = Math.ceil(b / a)==source?source+1:Math.ceil(b / a); res.push(`${1}/${sub}`); let deno = sub * b; let nume = a * sub - 1 * b; rest = `${nume}/${deno}`; if (nume == 0) { break; } } console.log(res.join("+")); } })();