【分析】
月份: 1 2 3 4 5 6 7 8...
对数: 1 1 2 3 5 8 13 21...
1+1 1+2 2+3 3+5
————————————————
版权声明:本文为CSDN博主「余余ღ」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/zx_666888/article/details/102834553
#include<stdio.h>
int main(void){
int N, month, x1 = 1, x2 = 1, x3 = 0;
scanf("%d", &N);
if (N == 1) // 1对至少需要1个月。
month = 1;
else
for (month = 2; x3 < N; month++){ // 斐波那契的迭代。
x3 = x1 + x2;
x1 = x2;
x2 = x3;
}
printf("%d", month);
return 0;
}