游客 Signup | Login
中文 | En

2810 - 打印Faibonacci数列

Faibonacci数列前几项为:0,1,1,2,3,5,8,……,其规律是从第三项起,每项均等于前两项之和。求前N项,并以每行5个数的格式输出。

Input

一行:一个整数n, 3<=n<=50

Output

若干行,每行5个数

Examples

Input

20

Output

0 1 1 2 3
5 8 13 21 34
55 89 144 233 377
610 987 1597 2584 4181

Solution C++

#include <cstdio>
//#include <cstdlib>
using namespace std;
int main()
{
	int old,new0,last,numi,n=1;
	scanf("%d",&numi);
	while(n<=numi)
	{
		if(n%5==1&&n!=1)
		    printf("\n");
		if(n==1)
		{
			old=0;
			new0=1;
			printf("%d ",old);
		}
		else
		{
			if(n==2)
			{
				printf("%d ",new0);
			}
			else
			{
				last=new0+old;
				if(n%5==0&&n!=1)
    				printf("%d",last);
				else
				    printf("%d ",last);
				old=new0;
				new0=last;
			}
		}
		n++;
	}
	printf("\n");
	//system("pause");
	return 0;
}

Time Limit 1 second
Memory Limit 128 MB
Discuss Stats
上一题 下一题