Solution: Fibonacci number
Month: 123,456,789
log: 112358132134
Why start from the month = 2? Because the Fibonacci number of 0 and 1 item that we have assigned, so starting from the second term.
#include <stdio.h>
int main()
{
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;
}