Advertisement
Diene

Untitled

Mar 1st, 2018
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.87 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int function(int n, int m, int a=1, int b=1){
  6.  
  7. if(n==1 && m==1){a==a; b==b;}
  8.  
  9. else if(n!=1 && m==1){
  10.  
  11.     if(n%2==0){return function(n/2,1,a++,b==b);}
  12.  
  13.     else if(n%2==1){return function(3*n+1,1,a++,b==b);}
  14.  
  15. }
  16.  
  17. else if(n==1 && m!=1){
  18.  
  19.     if(m%2==0){return function(1,m/2,a==a,b++);}
  20.  
  21.     else if(m%2==1){return function(1,3*m+1,a==a,b++);}
  22.  
  23. }
  24.  
  25. else if(n%2==0 && m%2==0){
  26.  
  27.         return function(n/2, m/2,a++,b++);
  28. }
  29.  
  30. else if(n%2==0 && m%2==1){
  31.  
  32.         return function(n/2, 3*m+1,a++,b++);
  33. }
  34.  
  35. else if(n%2==1 && m%2==0){
  36.  
  37.         return function(3*n+1, m/2, a++, b++);
  38. }
  39.  
  40. else if(n%2==1 && m%2==1){
  41.  
  42.         return function(3*n+1, 3*m+1,a++,b++);
  43. }
  44.  
  45. }
  46.  
  47. int main(){
  48.  
  49. int x,y;
  50.  
  51. scanf("%d %d", &x, &y);
  52.  
  53. int a=1, b=1;
  54.  
  55. function(x,y,a,b);
  56.  
  57. printf("%d %d %d", x, y, max(a, b));
  58.  
  59. return 0;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement