Problem Type : Ad Hoc
#include<stdio.h>
#include<algorithm>
using namespace std;
int main()
{
int a[100000],count;
long int i,n,m,s,j,k,temp,p,q;
while(scanf("%ld%ld",&n,&m)==2)
{
p=n;
q=m;
if(n>m)
{
temp=m;
m=n;
n=temp;
}
k=0;
for(i=n; i<=m; i++)
{
s=i;
count=0;
for(j=0;; j++)
{
if(s==1)
{
count++;
break;
}
else if(s%2==0)
{
s=s/2;
count++;
}
else if(s%2==1)
{
s=(3*s+1);
count++;
}
}
a[k]=count;
k++;
}
sort(a,a+k);
printf("%ld %ld %d\n",p,q,a[k-1]);
}
return 0;
}
#include<stdio.h>
#include<algorithm>
using namespace std;
int main()
{
int a[100000],count;
long int i,n,m,s,j,k,temp,p,q;
while(scanf("%ld%ld",&n,&m)==2)
{
p=n;
q=m;
if(n>m)
{
temp=m;
m=n;
n=temp;
}
k=0;
for(i=n; i<=m; i++)
{
s=i;
count=0;
for(j=0;; j++)
{
if(s==1)
{
count++;
break;
}
else if(s%2==0)
{
s=s/2;
count++;
}
else if(s%2==1)
{
s=(3*s+1);
count++;
}
}
a[k]=count;
k++;
}
sort(a,a+k);
printf("%ld %ld %d\n",p,q,a[k-1]);
}
return 0;
}
No comments:
Post a Comment