Hat ' s Fibonaccicrawling in process ... crawling failed Time limit:1000MS Memory Limit:32768KB 64bit IO Format:%i64d &%i64u
Description A Fibonacci sequence is calculated by adding the previous and the sequence, with the first and both members Being both 1.
F (1) = 1, f (2) = 1, f (3) = 1,f (4) = 1, f (n>4) = f (n-1) + f (n-2) + f (n-3) + f (n-4)
Your task is to take a number as input, and print that Fibonacci number.
Input each line would contain an integers. Process to end of file.
Output for each case, output of the result in a line.
Sample Input
100
Sample Output
4203968145672990846840663646 Note:no generated Fibonacci number in excess of 2005 digits would be in the test data, ie. F () = 66526 has 5 digits.
#include <iostream>
#include <stdio.h>
using namespace Std;
int a[8000][255]={{0}};
int n,k,ans,i,j,m;
int main ()
{
for (I=1; i<5; i++) a[i][1]=1;
for (i=5; i<8000; i++)
for (j=1; j<255; j + +)
{
A[I][J]+=A[I-1][J]+A[I-2][J]+A[I-3][J]+A[I-4][J];
a[i][j+1]+=a[i][j]/100000000;
a[i][j]=a[i][j]%100000000;//note here the bigger the better, I just started on 10000 operation, are WA, the corresponding below also should be%. 8d
}
while (scanf ("%d", &n)!=eof)
{
for (j=254; j>0; j--)
if (a[n][j]!=0)
{
K=j;
cout<<a[n][j];
Break
}
for (m=k-1; m>0; m--)
printf ("%.8d", a[n][m]);//must be handled this way, otherwise 111100001111 will only output 111101111
cout<<endl;
}
return 0;
}