兔子繁衍问题 (15 分)
一对兔子,从出生后第3个月起每个月都生一对兔子。小兔子长到第3个月后每个月又生一对兔子。假如兔子都不死,请问第1个月出生的一对兔子,至少需要繁衍到第几个月时兔子总数才可以达到N对?
输入格式:
输入在一行中给出一个不超过10000的正整数N。
输出格式:
在一行中输出兔子总数达到N最少需要的月数。
输入样例:
30
结尾无空行
输出样例:
9
结尾无空行
#include<stdio.h>
int main()
{
int N;
int mouth=0;
int mouth1= 1;
int mouth2= 1;
int count;
scanf("%d",&N);
if(N==1)
{
mouth = 1;
}
else if(N>1)
{
count = 1;mouth=2;
while(count<N)
{
count = mouth1 + mouth2;
mouth1 = mouth2;
mouth2 = count;
mouth++;
}
}
printf("%d",mouth);
return 0;
}