The 3n + 1 Problem

0 views
Skip to first unread message

May

unread,
Jul 1, 2011, 3:15:58 PM7/1/11
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;
}
Reply all
Reply to author
Forward
0 new messages