题解 | #统计每个月兔子的总数#
统计每个月兔子的总数
https://www.nowcoder.com/practice/1221ec77125d4370833fd3ad5ba72395
递归,born()函数初始兔子数量是1,每只兔子最终都会从出生后月份➕2开始生,所以循环这几个月份,兔子祖宗都要生一只崽,
所以最后就是在循环里面嵌套调用兔子出生函数即可。
const rl = require("readline").createInterface({ input: process.stdin }); var iter = rl[Symbol.asyncIterator](); const readline = async () => (await iter.next()).value; function bron(totalMon,bornMon){ let sum=1; for(let i=(bornMon+2);i<=(totalMon);i++){ sum=sum+bron(totalMon,i); } return sum; } (async () => { let n = await readline(); n=Number(n); console.log(bron(n,1)); })()