[Login|Register]
New post

Show post

Search forum

Read post
哪个地方有问题吗? [ Topic ] 2010-10-11 02:31:45 zsonglin
#include <iostream>

using namespace std;
int Length(int x)
{
int len=1;
while(x!=1)
{
     if(x%2==0)x=x/2;
     else
         x=(x*3+1);
     len++;
}
return len;
}
int main()
{

int a,b,max;
while(1)
{
    cin>>a>>b;
    max=Length(a);
for(int i=a;i<=b;i++)
{
if(Length(i)>=max)
  max=Length(i);
}
cout<<a<<' '<<b<<' '<<max<<endl;
}

}
Reply
Title
Message
(64K)
University of Science and Technology of China
Online Judge for ACM/ICPC
Processed in 1.7ms with 2 query(s).