Created
July 23, 2016 13:33
-
-
Save minhazmiraz/0b65fb4c5e813810ee246e2b1f2aca4a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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