UVa 100( 3n+1)
#include<bits/stdc++.h>
using namespace std;
int main()
{
ios_base :: sync_with_stdio(0);cin.tie(0);
//freopen("input.txt","r",stdin);
int i,j;
int count;
while(scanf("%d%d",&i,&j)==2)
{
int k,l,m;
int max=0;
l=i,m=j;
if(l>m)
{
int temp=l;
l=m;
m=temp;
}
for(k=l;k<=m;k++)
{
count=1;
int n=k;
while(n>1)
{
if(n&1) n=3*n+1;
else n/=2;
count++;
}
if(count>max) max=count;
}
cout<<i<<" "<<j<<" "<<max<<endl;
}
return 0;
}
Yes, it is!
ReplyDelete