Fibonacci
Time limit:1000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 4512 Accepted Submission (s): 2068
Problem Description2007 year has come. 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 inputs several digits 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 outputs).
Sample Input012345353637383940
Sample Output011235922714932415390863241023
Authordaringqq
Sourcehappy 2007
Recommend8600 | We have carefully selected several similar problems for you:1060 1286 1788 1787 1047
Exercises
This question takes the formula of the sequence: an= (1/√5) * [((1+√5)/2) ^n-((1-√5)/2) ^n] (n=1,2,3 ...)
#include <stdio.h>#include<math.h>intMain () {intN,i; intf[ +]={0,1,1}; DoubleA= (1.0+SQRT (5.0))/2.0; for(i=3; i<= -; i++)//Top 20 Items generatedF[i]=f[i-1]+f[i-2]; while(SCANF ("%d", &n)! =EOF) { if(n<= -) printf ("%d\n", F[n]); Else { Doubleans=-0.5*LOG10 (5.0) +n*log10 (a); intanswer; Ans=ans-floor (ANS);//take a decimal partans=pow (Ten, ans);//take power onceAnswer=(int) (ans* +);//Type Conversionsprintf ("%d\n", answer); } } return 0;}
HDU1568 Fibonacci Reasoning