Skip to content

Instantly share code, notes, and snippets.

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