VJ_兔子产子_斐波那契数列打表

从前有一对长寿兔子,它们每一个月生一对兔子,新生的小兔子两个月就长大了,在第二个月的月底开始生它们的下一代小兔子,这样一代一代生下去,求解兔子增长数量的数列。

Input

第1行 是测试数据的组数n,后面跟着n行输入。每组测试数据占1行,包括一个正整数a(1 <= a <= 20)

Output

输出有1行,每行输出对应一个输入。输出应是一个正整数序列,整数之间用空格分开。

Sample

Inputcopy Outputcopy
3
3
2
1
1 1 2
1 1
1

//
#include<bits/stdc++.h>
using namespace std;

const int N=33;
int ans[N];

void solve()
{
    ans[1]=ans[2]=0;
    for( int i=3;i<N;i++ )
    {
        ans[i]=ans[i-1]+ans[i-2];
    }
}

int main()
{
    solve();
    int n,x,i;
    while( cin>>n )
    {
        while( n-- )
        {
            cin>>x;
            for( i=1;i<=x;i++ )
            {
                if( i!=1 ) cout<<" ";
                cout<<ans[i];
            }
            cout<<endl;
        }
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_63173957/article/details/125101823
今日推荐