Skip to content

Instantly share code, notes, and snippets.

@minhazmiraz
Created July 23, 2016 13:33
Show Gist options
  • Save minhazmiraz/0b65fb4c5e813810ee246e2b1f2aca4a to your computer and use it in GitHub Desktop.
Save minhazmiraz/0b65fb4c5e813810ee246e2b1f2aca4a to your computer and use it in GitHub Desktop.
#include<stdio.h>
int cycle(int a)
{
int i=0;
while(1)
{
i++;
if(a==1)
break;
if(a%2!=0)
a=(3*a)+1;
else
a=a/2;
}
return i;
}
int main()
{
int a,b,c,temp,i;
while(scanf("%d%d",&a,&b)==2)
{
int max=0;
printf("%d %d ",a,b);
if(a>b)
{
temp=a;
a=b;
b=temp;
}
for(i=a;i<=b;i++)
{
c=cycle(i);
if(c>=max)
max=c;
}
printf("%d\n",max);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment