Problem Type : Number Theory
#include<stdio.h>
#define MAX 4003
#define len 1000
int fab[MAX][len];
void favonaccy()
{
int i,j;
fab[0][0]=0;
fab [1][0]=1;
for(i=2; i<MAX; i++)
{
for(j=0; j<len; j++)
{
fab [i][j]= fab[i][j]+fab[i-1][j]+fab[i-2][j];
if(fab[i][j]>9)
{
fab[i][j+1]=fab[i][j]/10;
fab[i][j]=fab[i][j]%10;
}
}
}
}
int main()
{
favonaccy();
int i,j,k,n;
while(scanf("%d",&n)==1)
{
;
for(i=len-1; i>=0; i--)
{
if(fab[n][i]!=0)
break;
}
for(j=i; j>=0; j--)
{
printf("%d",fab[n][j]);
}
printf("\n");
}
return 0;
}
#include<stdio.h>
#define MAX 4003
#define len 1000
int fab[MAX][len];
void favonaccy()
{
int i,j;
fab[0][0]=0;
fab [1][0]=1;
for(i=2; i<MAX; i++)
{
for(j=0; j<len; j++)
{
fab [i][j]= fab[i][j]+fab[i-1][j]+fab[i-2][j];
if(fab[i][j]>9)
{
fab[i][j+1]=fab[i][j]/10;
fab[i][j]=fab[i][j]%10;
}
}
}
}
int main()
{
favonaccy();
int i,j,k,n;
while(scanf("%d",&n)==1)
{
;
for(i=len-1; i>=0; i--)
{
if(fab[n][i]!=0)
break;
}
for(j=i; j>=0; j--)
{
printf("%d",fab[n][j]);
}
printf("\n");
}
return 0;
}
No comments:
Post a Comment