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+1

Posted by whus200532550008 at 2006-12-23 16:06:22
Int compute1(int i)
{
Int count=1,tmp=i;
While(tmp>1)
{
If(tmp %2 =0) tmp/=2;
Else tmp=3*tmp+1;
count++
}
Return count;
}
Int compute2(int i, int j)
{
int max=0,tmp;
for(k=i;k<=j;k++)
{ 
tmp=compute1(k)
if (max<tmp) max=tmp; 
}
Return max;
}

#include “stdio.h”
int main(void)
{
int I,j result;
While(scanf(%d,&i)!=null)
{
scanf(%d,&j);
result=compute2(I,j);
printf(“%d %d %d”,I,j,result);
}
}

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