info@sislbd.com +8801775 012 358

UVA Online Judge – 100 – The 3n + 1 problem

#include <stdio.h>
#include <conio.h>
int main()
{
long input1,input2,start,end,n,max;
long count;
while(scanf(“%ld%ld”,&input1,&input2)==2)
{
max=0;
if(input1 >= input2)
{
start=input2;
end=input1;
}
else
{
start=input1;
end=input2;
}
for(long i=start;i<=end;i++) { count=0; n=i; while(1) { count=count+1; if(n==1) break; else if(n%2==0) n=n/2; else n=3*n+1; } // End of while if(count >= max)
max=count;
} // End of for
//printf(“Maximum is : %ld”,max);
printf(“%ld %ld %ld\n”,input1,input2,max);
} // End of while
getch();
} // End of main

spectrum