Fibonacci number of columns from A to

Source: Internet
Author: User
Tags strcmp

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&GT;&GT;T1&GT;&GT;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]) &GT;LEN2) {flag2=1; Y=i-1; }} cout<<y-x+1<<endl; } return 0;}

  

Fibonacci number of columns from A to

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.