Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

3n

Posted by 420321460619891005 at 2010-06-30 10:04:15
#include <iostream>
#include <stdlib.h>

using namespace std;

int main()
{
    int n=4;
    int x,y;
	
	while((cin>>x>>y))
	{
        int MAX=1;
		if(x>10000||x<0||y>10000||y<0) 
		{
			exit(1);
		}
		cout<<x<<' '<<y<<' ';
		if(x>y) 
		{ 
			int temp=y;
			y=x;
			x=temp;
		}
        for(int i=x;i<=y;i++)
        {
            int k=1,s=i;
            while(s!=1)
            {
                if(s%2==1) 
					s=3*s+1;
                else 
					s=s/2;
                k++;
            }
            if(k>MAX) 
			{
				MAX=k;
			}
        }
        cout<<MAX<<endl;
	}  
	
	return 1;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator