西工大数据结构极简解法--010k阶斐波那契数列

题目描述

在这里插入图片描述

极简解法

#include<stdio.h>
int main()
{
	int q[110]={1},mod,max,ans[110]={0},flag=1;
	scanf("%d%d",&max,&mod);
	for(int j=0;j<100&&q[j%mod]<=max&&flag;j++)
	{
		ans[0]=q[j%mod];
		for(int i=j%mod+1;i<j%mod+mod&&q[i%mod]<=max&&flag;i++)
		{
			q[j%mod]+=q[i%mod];
			ans[i-j%mod]=q[i%mod];
			if(q[j%mod]>max)
			{
				flag=0;continue;
			}
		}
	}
	for(int j=0;j<mod;j++)
	{
		printf("%d ",ans[j]);
	}
}

猜你喜欢

转载自blog.csdn.net/weixin_45619006/article/details/107292391