fork download
  1. // header files
  2. #include<bits/stdc++.h>
  3. #include <cstdio>
  4. #include <string>
  5. #include <algorithm>
  6. #include <iostream>
  7. #define file freopen("in.txt","rt",stdin)
  8. using namespace std;
  9. template<class T> string convert(T _input) {stringstream blah;blah << _input;return blah.str();}
  10. struct Bigint
  11. {
  12. // representations and structures
  13. string a; // to store the digits
  14. int sign; // sign = -1 for negative numbers, sign = 1 otherwise
  15. // constructors
  16. Bigint() {} // default constructor
  17. Bigint( string b )
  18. {
  19. (*this) = b; // constructor for string
  20. }
  21. // some helpful methods
  22. int size() // returns number of digits
  23. {
  24. return a.size();
  25. }
  26. Bigint inverseSign() // changes the sign
  27. {
  28. sign *= -1;
  29. return (*this);
  30. }
  31. Bigint normalize( int newSign ) // removes leading 0, fixes sign
  32. {
  33. for( int i = a.size() - 1; i > 0 && a[i] == '0'; i-- )
  34. a.erase(a.begin() + i);
  35. sign = ( a.size() == 1 && a[0] == '0' ) ? 1 : newSign;
  36. return (*this);
  37. }
  38. // assignment operator
  39. void operator = ( string b ) // assigns a string to Bigint
  40. {
  41. a = b[0] == '-' ? b.substr(1) : b;
  42. reverse( a.begin(), a.end() );
  43. this->normalize( b[0] == '-' ? -1 : 1 );
  44. }
  45. // conditional operators
  46. bool operator < ( const Bigint &b ) const // less than operator
  47. {
  48. if( sign != b.sign ) return sign < b.sign;
  49. if( a.size() != b.a.size() )
  50. return sign == 1 ? a.size() < b.a.size() : a.size() > b.a.size();
  51. for( int i = a.size() - 1; i >= 0; i-- ) if( a[i] != b.a[i] )
  52. return sign == 1 ? a[i] < b.a[i] : a[i] > b.a[i];
  53. return false;
  54. }
  55. bool operator == ( const Bigint &b ) const // operator for equality
  56. {
  57. return a == b.a && sign == b.sign;
  58. }
  59. // mathematical operators
  60. Bigint operator + ( Bigint b ) // addition operator overloading
  61. {
  62. if( sign != b.sign ) return (*this) - b.inverseSign();
  63. Bigint c;
  64. for(int i = 0, carry = 0; i<a.size() || i<b.size() || carry; i++ )
  65. {
  66. carry+=(i<a.size() ? a[i]-48 : 0)+(i<b.a.size() ? b.a[i]-48 : 0);
  67. c.a += (carry % 10 + 48);
  68. carry /= 10;
  69. }
  70. return c.normalize(sign);
  71. }
  72. Bigint operator - ( Bigint b ) // subtraction operator overloading
  73. {
  74. if( sign != b.sign ) return (*this) + b.inverseSign();
  75. int s = sign;
  76. sign = b.sign = 1;
  77. if( (*this) < b ) return ((b - (*this)).inverseSign()).normalize(-s);
  78. Bigint c;
  79. for( int i = 0, borrow = 0; i < a.size(); i++ )
  80. {
  81. borrow = a[i] - borrow - (i < b.size() ? b.a[i] : 48);
  82. c.a += borrow >= 0 ? borrow + 48 : borrow + 58;
  83. borrow = borrow >= 0 ? 0 : 1;
  84. }
  85. return c.normalize(s);
  86. }
  87. Bigint operator * ( Bigint b ) // multiplication operator overloading
  88. {
  89. Bigint c("0");
  90. for( int i = 0, k = a[i] - 48; i < a.size(); i++, k = a[i] - 48 )
  91. {
  92. while(k--) c = c + b; // ith digit is k, so, we add k times
  93. b.a.insert(b.a.begin(), '0'); // multiplied by 10
  94. }
  95. return c.normalize(sign * b.sign);
  96. }
  97. Bigint operator / ( Bigint b ) // division operator overloading
  98. {
  99. if( b.size() == 1 && b.a[0] == '0' ) b.a[0] /= ( b.a[0] - 48 );
  100. Bigint c("0"), d;
  101. for( int j = 0; j < a.size(); j++ ) d.a += "0";
  102. int dSign = sign * b.sign;
  103. b.sign = 1;
  104. for( int i = a.size() - 1; i >= 0; i-- )
  105. {
  106. c.a.insert( c.a.begin(), '0');
  107. c = c + a.substr( i, 1 );
  108. while( !( c < b ) ) c = c - b, d.a[i]++;
  109. }
  110. return d.normalize(dSign);
  111. }
  112. Bigint operator % ( Bigint b ) // modulo operator overloading
  113. {
  114. if( b.size() == 1 && b.a[0] == '0' ) b.a[0] /= ( b.a[0] - 48 );
  115. Bigint c("0");
  116. b.sign = 1;
  117. for( int i = a.size() - 1; i >= 0; i-- )
  118. {
  119. c.a.insert( c.a.begin(), '0');
  120. c = c + a.substr( i, 1 );
  121. while( !( c < b ) ) c = c - b;
  122. }
  123. return c.normalize(sign);
  124. }
  125. void print()
  126. {
  127. if( sign == -1 ) putchar('-');
  128. for( int i = a.size() - 1; i >= 0; i-- ) putchar(a[i]);
  129. }
  130. };
  131.  
  132. int main()
  133. {
  134. Bigint arr[1009];
  135. int n,i=1;
  136. Bigint f,s,t,a,b;
  137. f = "0";
  138. s = "1";
  139.  
  140. while(i<=500)
  141. {
  142. t = f + s;
  143.  
  144.  
  145. arr[i] = t;
  146. f = s;
  147. s = t;
  148. i++;
  149. }
  150. string str,str1;
  151. while(cin>>str>>str1)
  152. {
  153. a = str;
  154. b = str1;
  155. if(str=="0" && str1=="0")
  156. break;
  157. int l=1,r;
  158. for(int i=1;arr[i]<a || arr[i]==a;i++)
  159. {
  160. l = i;
  161. }
  162. int cnt = 0;
  163. for(int i=l;arr[i]<b || arr[i]==b;i++)
  164. {
  165. cnt++;
  166. }
  167. if(str=="0")
  168. {
  169. printf("%d\n",cnt);
  170. continue;
  171. }
  172. if(arr[l]==a)
  173. printf("%d\n",cnt);
  174. else
  175. printf("%d\n",cnt-1);
  176. }
  177.  
  178.  
  179. return 0;
  180. }
  181.  
Success #stdin #stdout 0s 15248KB
stdin
Standard input is empty
stdout
Standard output is empty