Description
2007 came. After 2006 years of cultivation, mathematical prodigy Zouyu finally put 0 to 100000000 of Fibonacci series
The values (f[0]=0,f[1]=1;f[i] = f[i-1]+f[i-2] (i>=2) are all backed down.
Next, Codestar decided to test him, so each asked him a number, he will say the answer, but some numbers are too long. So the provision of more than 4 people as long as the first 4 can be said, but Codestar himself cannot remember. So he decided to write a program to test whether Zouyu said it was correct.
Input
Enter several numbers n (0 <= n <= 100000000), one row per digit. Read the end of the file.
Output
Output F[N] The first 4 digits (if less than 4 digits, all output).
Sample Input
012345353637383940
Sample Output
011235922714932415390863241023
#include <iostream>#include<cstdio>#include<cmath>using namespacestd;intMain () {inti,n,a[ A],len; Doubles,d; a[0]=0; a[1]=1; for(i=2;i< A; i++) A[i]=a[i-1]+a[i-2]; while(SCANF ("%d", &n)! =EOF) { if(n< +) printf ("%d\n", A[n]); Else{s=LOG10 (1.0/SQRT (5)) +n*log10 (1+SQRT (5))/2.0); Len=(int) s; D=s+3-Len; printf ("%d\n",(int) Pow (Ten, D)); } } return 0;}
Fibonacci Closed Formula