Advertisement
Mohammad_Dipu_Sultan

UVA 10183 - How Many Fibs?

Feb 17th, 2021
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.05 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. // #include <iostream>
  3. // #include <cstdio>
  4. // #include <cstdlib>
  5. // #include <algorithm>
  6. // #include <cmath>
  7. // #include <vector>
  8. // #include <set>
  9. // #include <map>
  10. // #include <queue>
  11. // #include <ctime>
  12. // #include <cassert>
  13. // #include <complex>
  14. // #include <string>
  15. // #include <cstring>
  16. // #include <queue>
  17. // #include <bitset>
  18.  
  19. using namespace std;
  20. typedef long long           ll;
  21. typedef unsigned long long  ull;
  22.  
  23. #define ff                  first
  24. #define ss                  second
  25. #define pb                  push_back
  26. #define mp                  make_pair
  27. #define in                  insert
  28. #define vi                  vector< int >
  29. #define vll                 vector< ll >
  30.  
  31.  
  32. #define f0(b)               for(int i=0;i<(b);i++)
  33. #define f00(b)              for(int j=0;j<(b);j++)
  34. #define f1(b)               for(int i=1;i<=(b);i++)
  35. #define f11(b)              for(int j=1;j<=(b);j++)
  36. #define f2(a,b)             for(int i=(a);i<=(b);i++)
  37. #define f22(a,b)            for(int j=(a);j<=(b);j++)
  38. #define RFOR(i,x,y)         for(int i=x;i>=y;i--)
  39. #define unq(v)              sort(all(v)),(v).resize(unique(all(v))-v.begin())
  40. #define all(v)              v.begin(),v.end()
  41. #define rall(v)             v.rbegin(),v.rend()
  42. #define reversed(s)         reverse(s.begin(), s.end())
  43.  
  44. #define testcase            ll t; cin>>t; while (t--)
  45. #define vout(v)             for(int ind=0;ind<v.size();ind++){ cout<<v[ind]; if(ind<v.size()-1) cout<<' '; else cout<<endl;}
  46. #define arrout(arr,i,x,y)   for(int i=x;i<=y;i++){ cout<<arr[i]; if(i<y) cout<<' '; else cout<<endl;}
  47. #define READ()              freopen("input.txt", "r", stdin)
  48. #define WRITE()             freopen("output.txt", "w", stdout)
  49.  
  50. #define sci(n)              scanf("%d",&n)
  51. #define scii(x,y)           scanf("%d %d",&x,&y)
  52.  
  53.  
  54. #define scl(n)              scanf("%lld",&n)
  55. #define scll(x,y)           scanf("%lld %lld",&x,&y)
  56. #define gtl(x)              getline(cin, (x))
  57.  
  58. #define PI                  acos(-1)
  59. #define CLR(x, y)           memset(x, y, sizeof(x))
  60. #define Precision(a)        cout << fixed << setprecision(a)
  61. #define Flame()             ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
  62. #define MAXP                10000
  63. #define MOD                 1e9+7//10000007
  64. #define EPS                 1e-7
  65.  
  66. template <typename T> T Sqr(T x)
  67. {
  68.     T n = x * x ;
  69.     return n ;
  70. }
  71. template <typename T> T Pow(T B,T P)
  72. {
  73.     if(P==0) return 1;
  74.     if(P&1) return B*Pow(B,P-1);
  75.     else return Sqr(Pow(B,P/2));
  76. }
  77. template <typename T> T Abs(T a)
  78. {
  79.     if(a<0)return -a;
  80.     else return a;
  81. }
  82. template <typename T> T Gcd(T a,T b)
  83. {
  84.     if(a<0)return Gcd(-a,b);
  85.     if(b<0)return Gcd(a,-b);
  86.     return (b==0)?a:Gcd(b,a%b);
  87. }
  88. template <typename T> T Lcm(T a,T b)
  89. {
  90.     if(a<0)return Lcm(-a,b);
  91.     if(b<0)return Lcm(a,-b);
  92.     return a*(b/Gcd(a,b));
  93. }
  94. template <typename T> T BigMod (T b,T p,T m)
  95. {
  96.     if (p == 0) return 1;
  97.     if (p%2 == 0)
  98.     {
  99.         T s = BigMod(b,p/2,m);
  100.         return ((s%m)*(s%m))%m;
  101.     }
  102.     return ((b%m)*(BigMod(b,p-1,m)%m))%m;
  103. }
  104. template <typename T> inline string ToBinary(T n)
  105. {
  106.     string r ;
  107.     while(n != 0)
  108.     {
  109.         r = ( n % 2 == 0 ? "0" : "1" ) + r ;
  110.         n >>= 1;
  111.     }
  112.     return r ;
  113. }
  114. long long BinaryToDecimal(string s)
  115. {
  116.     int len = s.size();
  117.     long long n = 0, p = 1;
  118.     for (int i = len - 1; i >= 0; i--, p *= 2) n += p * (s[i] - '0');
  119.     return n;
  120. }
  121.  
  122. int Strtoint(string str)
  123. {
  124.     stringstream ss(str);
  125.     int x = 0;
  126.     ss >> x ;
  127.     return x ;
  128. }
  129. string Intostr(int x)
  130. {
  131.     stringstream ss;
  132.     ss << x;
  133.     string str = ss.str();
  134.     return str;
  135. }
  136.  
  137. #define bug printf("**!\n")
  138. #define D(x)            cerr << __LINE__ << ": " #x " = " << (x) << '\n'
  139. #define DD(x, y)        cerr << __LINE__ << ": " #x " = " << (x) << ", " #y " = " << (y) << '\n'
  140. #define DDD(x, y, z)    cerr << __LINE__ << ": " #x " = " << (x) << ", " #y " = " << (y) << ",  " #z " = " << (z) << '\n'
  141. string fib[MAXP];
  142. string Add_sum(string str1,string str2)
  143. {
  144.  
  145.     if (str1.length() > str2.length())
  146.         swap(str1, str2);
  147.  
  148.  
  149.     int n1 = str1.length(), n2 = str2.length();
  150.     string str = "";
  151.  
  152.     reverse(str1.begin(), str1.end());
  153.     reverse(str2.begin(), str2.end());
  154.     ll carry = 0;
  155.     for (int i=0; i<n1; i++)
  156.     {
  157.         // Do school mathematics, compute sum of
  158.         // current digits and carry
  159.         int sum = ((str1[i]-'0')+(str2[i]-'0')+carry);
  160.         str.push_back(sum%10 + '0');
  161.  
  162.         // Calculate carry for next step
  163.         carry = sum/10;
  164.     }
  165.  
  166.     // Add remaining digits of larger number
  167.     for (int i=n1; i<n2; i++)
  168.     {
  169.         int sum = ((str2[i]-'0')+carry);
  170.         str.push_back(sum%10 + '0');
  171.         carry = sum/10;
  172.     }
  173.  
  174.     // Add remaining carry
  175.     if (carry)
  176.         str.push_back(carry+'0');
  177.  
  178.     // reverse resultant string
  179.     reverse(str.begin(), str.end());
  180.  
  181.     return str;
  182. }
  183.  
  184. void Fibs()
  185. {
  186.     fib[0]="0";
  187.     fib[1]="1";
  188.     for(ll i=2; i<=1000; i++)
  189.     {
  190.         fib[i]=Add_sum(fib[i-1], fib[i-2]);
  191.     }
  192. }
  193.  
  194. bool ckr1(string a, string b)
  195. {
  196.     if(a.length()!=b.length())
  197.     {
  198.         if(a.length()>b.length()) return 1;
  199.         else return 0;
  200.     }
  201.     for(ll i=0; i<a.length(); i++)
  202.     {
  203.         if(a[i]!=b[i])
  204.         {
  205.             if(a[i]>b[i]) return 1;
  206.             else return 0;
  207.         }
  208.     }
  209.     return 1;
  210. }
  211. bool ckr2(string a, string b)
  212. {
  213.     if(a.length()!=b.length())
  214.     {
  215.         if(a.length()>b.length()) return 0;
  216.         else return 1;
  217.     }
  218.     for(ll i=0; i<a.length(); i++)
  219.     {
  220.         if(a[i]!=b[i])
  221.         {
  222.             if(a[i]>b[i]) return 0;
  223.             else return 1;
  224.         }
  225.     }
  226.     return 1;
  227. }
  228. int main()
  229. {
  230.     Flame();
  231.     Fibs();
  232.     string a,b;
  233.     while(cin>>a>>b)
  234.     {
  235.         if(a=="0" && b=="0") break;
  236.         ll cnt=0;
  237.         for(ll i=2; i<=1000; i++)
  238.         {
  239.             if(ckr1(fib[i],a) && ckr2(fib[i],b))
  240.             {
  241.                 cnt++;
  242.             }
  243.         }
  244.         cout << cnt << endl;
  245.     }
  246.     return 0;
  247. }
  248.  
  249.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement