Hey, I typed every fib into the table first, and then it was very violent to find it within the range.
# Include <iostream> # include <algorithm> # include <string> # include <math. h> # define maxn 600 using namespace STD; int sum [maxn + 1] [50], len1 [maxn + 1]; int A [50], B [50], LA, Lb; char str1 [110], str2 [110]; void Init () {sum [0] [0] = 0; len1 [0] = 0; sum [1] [0] = 1; len1 [1] = 0; sum [2] [0] = 2; len1 [2] = 0; for (INT I = 3; I <= maxn; I ++) {int K = 0, J; For (j = 0; j <= len1 [I-2]; j ++) {int T = K + sum [I-1] [J] + sum [I-2] [J]; k = T/10000; sum [I] [J] = T % 10000;} while (J-1 )! = Len1 [I-1]) {int T = K + sum [I-1] [J]; k = T/10000; sum [I] [J] = T % 10000; j ++;} while (k) {int T = K; k = T/10000; sum [I] [J] = T % 10000; j ++ ;} len1 [I] = J-1;} int compare (int * s, int L, int num) {If (L> len1 [num]) return 1; else if (L <len1 [num]) Return-1; for (INT I = L; I> = 0; I --) {// cout <s [I] <''<sum [num] [I] <Endl; if (s [I]> sum [num] [I]) return 1; else if (s [I] <sum [num] [I]) Return-1 ;} return 0;} void solve () {int T1 = 1; while (La <len1 [T1]) T1 ++; // find the first fiber I with a length greater than or equal to the left interval; for (I = T1; I <= maxn; I ++) // locate the first FIB {If (compare (A, La, I) greater than the left interval <= 0) break;} Int J; For (j = I; j <= maxn; j ++) // locate the first FIB {If (compare (B, LB, j) <0) break;} printf ("% d \ n", J-I);} int main () {int N, Len; Init (); while (scanf ("% S % s", str1, str2) = 2) {If (strcmp (str1, "0") = 0 & strcmp (str2, "0") = 0) break; int S1 = strlen (str1), S2 = strlen (str2); La = lB = 0; For (INT I = s1-1; i> = 0; I-= 4) // storage method for converting a string to a large number. Four digits are saved into an integer Array {int S = 0; for (Int J = 0; j <4 & (I-j)> = 0; j ++) S + = (INT) Pow (10.0, J) * (str1 [I-j]-'0'); A [la ++] = s;} For (INT I = s2-1; I> = 0; i-= 4) {int S = 0; For (Int J = 0; j <4 & (I-j)> = 0; j ++) S + = (INT) Pow (10.0, j) * (str2 [I-j]-'0'); B [LB ++] = s;} La --; LB --; solve ();} return 0 ;}