May
unread,Jul 1, 2011, 3:15:58 PM7/1/11Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to ACM-CPC-MUST
/*
Question ID: 100 (The 3n + 1 Problem)
Tool: DevC++ 7.3.1.3
Rank: 8468
Time: 0.592
*/
#include <stdio.h>
int main(void){
unsigned long i,j,k,max,count,n;
while(scanf("%ld %ld",&i,&j)){
printf("%ld %ld ",i,j);
if(i>j){
unsigned long temp = i;
i=j;
j=temp;
}
max=0;
k=i;
while(k<=j){
n = k;
count = 1;
while(n!=1){
n = n&1?(n*3+1):(n>>1);
count++;
}
max = max>count?max:count;
k++;
}
printf("%ld\n",max);
}
return 0;
}