Saleh127

UVA 10183

Sep 20th, 2020
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define test int t; cin>>t; for(int cs=1;cs<=t;cs++)
  5.  
  6. string fiv[10000];
  7.  
  8. string addd(string a,string c)
  9. {
  10.  
  11. ll s1,s2,l,i,j,k=0;
  12. string sum="";
  13.  
  14. reverse(a.begin(),a.end());
  15. reverse(c.begin(),c.end());
  16.  
  17. s1=a.size();
  18. s2=c.size();
  19. l=max(s1,s2);
  20.  
  21. for(i=0; i<l; i++)
  22. {
  23. if(i<s1)
  24. {
  25. k+=(a[i]-'0');
  26. }
  27. if(i<s2)
  28. {
  29. k+=(c[i]-'0');
  30. }
  31. sum+=((k%10)+'0');
  32. k/=10;
  33. }
  34.  
  35. if(k)
  36. {
  37. sum+=(k+'0');
  38. }
  39. reverse(sum.begin(),sum.end());
  40.  
  41. return sum;
  42. }
  43.  
  44. void fivonacci()
  45. {
  46. fiv[0]="0";
  47. fiv[1]="1";
  48. for(ll i=2; i<=1000; i++)
  49. {
  50. fiv[i]=addd(fiv[i-1],fiv[i-2]);
  51. }
  52. }
  53.  
  54. bool check1(string a,string c)
  55. {
  56. ll i,j;
  57.  
  58. if(a.size()!=c.size())
  59. {
  60. if(a.size()>c.size()) return 1;
  61. else return 0;
  62. }
  63. for(i=0; i<a.size(); i++)
  64. {
  65. if(a[i]!=c[i])
  66. {
  67. if(a[i]>c[i]) return 1;
  68. else return 0;
  69. }
  70. }
  71.  
  72. return 1;
  73. }
  74.  
  75. bool check2(string a,string c)
  76. {
  77. ll i,j;
  78.  
  79. if(a.size()!=c.size())
  80. {
  81. if(a.size()>c.size()) return 0;
  82. else return 1;
  83. }
  84. for(i=0; i<a.size(); i++)
  85. {
  86. if(a[i]!=c[i])
  87. {
  88. if(a[i]>c[i]) return 0;
  89. else return 1;
  90. }
  91. }
  92.  
  93. return 1;
  94. }
  95.  
  96. int main()
  97. {
  98. ios_base::sync_with_stdio(0);
  99. cin.tie(0);
  100. cout.tie(0);
  101.  
  102. fivonacci();
  103.  
  104. string a,c;
  105. ll i,j,k,l;
  106. while(cin>>a>>c)
  107. {
  108. l=0;
  109. if(a=="0" && c=="0") break;
  110. for(i=2; i<800; i++)
  111. {
  112. if(check1(fiv[i],a) && check2(fiv[i],c))
  113. {
  114. l++;
  115. }
  116. }
  117. cout<<l<<endl;
  118. }
  119.  
  120. return 0;
  121. }
  122.  
Advertisement
Add Comment
Please, Sign In to add comment