View Code of Problem 331

#include<stdio.h>
int main(void)
{
	int x,y;
	while(scanf("%d %d",&x,&y)!=EOF)
	{
		int a,b;
		if(x>y){
			a=y;b=x;
		}
		else{
			a=x;b=y;	
		}
		int max=0;//每次的循环次数要初始化 
	for(int i=a;i<=b;i++)
	{	
		int sum=1;
		int t=i;
		while(t>1)
		{	sum++;
			if(t%2==0)
			{
				t=t/2;
			}
			else
			{
				t=t*3+1;	
			}	
		}
		if(max<sum)
		{
			max=sum;
		}
	}
	printf("%d %d %d\n",x,y,max); 
	}
	
	return 0;
 } 

Double click to view unformatted code.


Back to problem 331