Description
We define the Fibonacci sequence as follows: F1=1F2=2F (n) =f (n-1) +f (n-2) (n>=3) Now, given two numbers a and B, calculate how many Fibonacci numbers are between A and B (including boundaries).
Input
The input contains more than one set of test data, each set of test data is two nonnegative integers a and B, when a and B are equal to 0 o'clock, the program ends. 0<=A<=B<=10^100, note that A and B do not have a leading 0 (that is, the first 0).
Output
The number of outputs between A and B (satisfying a<=f (i) <=b).
Sample Input
10 1001234567890 98765432100 0
Sample Output
54
Note: There is a problem with the code, the system is not (HDU 1316)
#include <iostream> #include <cstdio> #include <algorithm> #include <cmath> #include < String.h> #include <malloc.h>using namespace std;void Add (char* a,char* b,char* c) {int i,j,k,max,min,n,temp; Char *s,*pmax,*pmin; Max=strlen (a); Min=strlen (b); if (max<min) {Temp=max; Max=min; Min=temp; Pmax=b; Pmin=a; } else {pmax=a; Pmin=b; } s= (char*) malloc (sizeof (char) * (max+1)); s[0]= ' 0 '; for (I=min-1,j=max-1,k=max; i>=0; i--, J--, k--) s[k]=pmin[i]-' 0 ' +pmax[j]; for (; j>=0; J--, k--) s[k]=pmax[j]; for (I=max; i>=0; i--) if (s[i]> ' 9 ') {s[i]-=10; s[i-1]++; } if (s[0]== ' 0 ') {for (i=0; i<=max; i++) c[i-1]=s[i]; c[i-1]= ' + '; } else {for (i=0; i<=max; i++) c[i]=s[i]; c[i]= ' + '; } free (s);} Char A[360][360];int main () {int i,x,y,Flag1,flag2; Char t1[105],t2[105]; strcpy (A[1], "1"); strcpy (A[2], "2"); for (i=3;i<360;i++) Add (A[i-1],a[i-2],a[i]); while (CIN>>T1>>T2) {if (strcmp (T1, "0") ==0&&strcmp (T2, "0") ==0) break; flag1=0;flag2=0; int Len1=strlen (t1); int Len2=strlen (t2); for (i=1;i<360;i++) {if (Flag1==0&&strlen (A[i]) ==len1) {if (strcmp (a [i],t1) >=0) {flag1=1; X=i; }} if (Flag1==0&&strlen (A[i]) >len1) {flag1=1; X=i; } if (Flag2==0&&strlen (A[i]) ==len2) {if (strcmp (A[I],T2) >=0) {flag2=1; Y=i; if (strcmp (A[I],T2) >0) y--; }} if (Flag2==0&&strlen (A[i]) >LEN2) {flag2=1; Y=i-1; }} cout<<y-x+1<<endl; } return 0;}
Fibonacci number of columns from A to