this problem is straight-forward. just find and choose the best value.
use unsigned long or long long.The largest value in the sequence will not be larger than can be accomodated in a 32-bit Pascal LongInt or C long
and ...
Code: Select all
max=0;
for (k=i;k<=j;k++) {
count=0;
p=k;
while (1)
{
if (p%2==0)
p=p/2;
else
p=3*p+1;
count=count+1;
if(p==1)break;
}
if(max<count) {
max=count;
gen=k;
}
count=0;
}
1. Don't use count and max as variable name. sometimes it creates problem if defined as global.
2. Think simple

3. It's better if you can find your bug yourself.
4. Always search the board first. Check with board input. If further confusion exists, http://uvatoolkit.com/problemssolve.php