View Code of Problem 331

//#include<iostream>
//#include<cmath>
//#include<cstring>
//#include<algorithm>
//using namespace std;
#include<stdio.h>
int main()
{
	int n,m;
	while(scanf("%d %d",&n,&m)!=EOF)
	{
		int a,b;
		if(n>m){
			a=m;b=n;
		}
		else{
			a=n;b=m;	
		}
		int max=0;
		for(int i=a;i<=b;i++)
		{
			int count=1;
			int j=i;
			while(j>1){
				count++;
				if(j%2==0)
					j/=2;
				else j=j*3+1;
			} 
			if(count>max)
				max=count;
		}
		printf("%d %d %d\n",n,m,max);
	}
    return 0;
}//main

Double click to view unformatted code.


Back to problem 331