Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- int function(int n, int m, int a=1, int b=1){
- if(n==1 && m==1){a==a; b==b;}
- else if(n!=1 && m==1){
- if(n%2==0){return function(n/2,1,a++,b==b);}
- else if(n%2==1){return function(3*n+1,1,a++,b==b);}
- }
- else if(n==1 && m!=1){
- if(m%2==0){return function(1,m/2,a==a,b++);}
- else if(m%2==1){return function(1,3*m+1,a==a,b++);}
- }
- else if(n%2==0 && m%2==0){
- return function(n/2, m/2,a++,b++);
- }
- else if(n%2==0 && m%2==1){
- return function(n/2, 3*m+1,a++,b++);
- }
- else if(n%2==1 && m%2==0){
- return function(3*n+1, m/2, a++, b++);
- }
- else if(n%2==1 && m%2==1){
- return function(3*n+1, 3*m+1,a++,b++);
- }
- }
- int main(){
- int x,y;
- scanf("%d %d", &x, &y);
- int a=1, b=1;
- function(x,y,a,b);
- printf("%d %d %d", x, y, max(a, b));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement