//Problem link >>http://uva.onlinejudge.org/external/1/100.html
/// nothing to say ... our most honorable UVA problem (as stays right in the first of giant uva-problem list )... i solved that very lately ... ignoring the first !!
#include <iostream>
#include <cstdio>
using namespace std ;
int main ()
{
int a , b , i ;
while (cin>>a>>b)
{
cout<<a<<" "<<b ;
if (a>b) swap(a,b) ;
long long int res=0 ;
for (i=a ; i<=b ;i++)
{
long long int x = i , cnt =1 ;
while (x>1)
{
if (x%2) x=3*x+1 ;
else x=x/2 ;
cnt++ ;
}
res=max(res,cnt) ;
}
cout<<" "<<res<<endl ;
}
return 0 ;
}
/// nothing to say ... our most honorable UVA problem (as stays right in the first of giant uva-problem list )... i solved that very lately ... ignoring the first !!
#include <iostream>
#include <cstdio>
using namespace std ;
int main ()
{
int a , b , i ;
while (cin>>a>>b)
{
cout<<a<<" "<<b ;
if (a>b) swap(a,b) ;
long long int res=0 ;
for (i=a ; i<=b ;i++)
{
long long int x = i , cnt =1 ;
while (x>1)
{
if (x%2) x=3*x+1 ;
else x=x/2 ;
cnt++ ;
}
res=max(res,cnt) ;
}
cout<<" "<<res<<endl ;
}
return 0 ;
}
No comments:
Post a Comment