养兔子

养兔子

Time Limit: 1000MS Memory Limit: 65536KB

Submit Statistic

Problem Description

一对成熟的兔子每天能且只能产下一对小兔子,每次都生一公一母,每只小兔子的成熟期是1天,小兔子出生后隔一天才能再生小兔子。第一天某人领养了一对成熟的兔子,一公一母,请问第N天以后,他将会得到多少对兔子。

Input

测试数据包括多组,每组一行,为整数n(1≤n≤90)。
输入以0结束。

Output

对应输出第n天有几对兔子(假设没有兔子死亡现象,而且是一夫一妻制)。

Example Input

1
2
0

Example Output

1
2

Hint

数据类型可以用64位整数:long long

Author

majia

#include <stdio.h>
#include <stdlib.h>


int main()
{
    int n, i;
    long long int a[10000];
    while(scanf("%d", &n) != EOF)
    {
        if(n == 0)
        {
            break;
        }
        else
        {
        a[1] = 1;
        a[2] = 2;
        for(i = 3; i <= n; i++)
        {
            a[i] = a[i-1]+a[i-2];
        }
        printf("%lld\n", a[n]);
        }
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_40915439/article/details/79161850