7-39 兔子繁衍问题 (15分)
一对兔子,从出生后第3个月起每个月都生一对兔子。小兔子长到第3个月后每个月又生一对兔子。假如兔子都不死,请问第1个月出生的一对兔子,至少需要繁衍到第几个月时兔子总数才可以达到N对?
输入格式:
输入在一行中给出一个不超过10000的正整数N。
输出格式:
在一行中输出兔子总数达到N最少需要的月数。
输入样例:
30
输出样例:
9
一下代码仅供参考
#include<stdio.h>
#include<math.h>
int main(){
int n,amount=1,n_month=1,one_month=1,two_month=0,three_month=0;
scanf("%d",&n);
while(amount<n){
n_month++;
three_month+=two_month;
two_month=one_month;
one_month=three_month;
amount=one_month+two_month+three_month;
}
printf("%d",n_month);
return 0;
}
2021-01-27
最新推荐文章于 2023-07-18 19:30:37 发布