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

help me!!

Posted by hbu_jack at 2006-08-19 10:10:57 on Problem 1207
it is WA.
why??

#include<iostream>
using namespace std;
long int fun(long int n,long int i)
{
	if(n==1)return i;
	if(n%2==0)
		return fun(n/2,i+1);
	else return fun(3*n+1,i+1);
}
int main()
{
	long int a,b;
	int max=1;
	long int temp;
	while(cin>>a>>b)
    {
		cout<<a<<" "<<b<<" ";
		if(a>b){
			temp=a;
			a=b;
			b=temp;
				}
		for(int i=a;i<=b;++i)
	{
		long int j;
		j=fun(i,1);
		if(max<j)max=j;
	}
	cout<<max<<endl;
	}
	return 0;

	
}

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