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

Re:用我这个试试吧

Posted by whus200532590183 at 2006-12-24 19:24:25 on Problem 1207
In Reply To:用我这个试试吧 Posted by:Lighting at 2006-05-05 17:35:54
> #include <stdio.h>
> 
> unsigned long getl(int n)
> {
> 	unsigned long result=0;
> 	unsigned long r=n;
> 	while(r>1)
> 	{
> 		if(r%2==0)
> 		{
> 			r/=2;
> 			result++;
> 			continue;
> 		}
> 		if(r%2==1)
> 		{
> 			r=r*3+1;
> 			result++;
> 			continue;
> 		}
> 	}
> 	return(result);
> }
> 
> void main()
> {
> 	int i,j,k;
> 	int m,n;
> 	unsigned long max=0,temp;
> 	while(scanf("%d %d",&i,&j)!=EOF)
> 	{
> 		max=0;
> 		m=i>j?j:i;
> 		n=i>j?i:j;
> 		for(k=m;k<=n;k++)
> 		{
> 			temp=getl(k);
> 			if(temp>max)
> 				max=temp;
> 		}
> 		printf("%d %d %ld\n",i,j,max+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