#include <stdio.h>
int collatz(int a1, int *amax)
{
int count;
count = 1;
*amax = a1;
for(;;) {
if (a1 == 1) {
break;
}
count++;
if (a1 % 2 == 0) {
a1 /= 2;
} else {
a1 = a1 * 3 + 1;
}
if (a1 > *amax) {
*amax = a1;
}
}
return count;
}
int main()
{
int i;
int amax;
int maxlen;
int maxini;
int len;
maxlen = 0;
maxini = 0;
for (i = 2; i <= 100000; i++) {
len = collatz(i, &amax);
if (len > maxlen) {
maxlen = len;
maxini = i;
}
}
printf("%d, %d\n", maxini
, maxlen
); return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CgppbnQgY29sbGF0eihpbnQgYTEsIGludCAqYW1heCkKewppbnQgY291bnQ7Cgpjb3VudCA9IDE7CiphbWF4ID0gYTE7CmZvcig7OykgewogIGlmIChhMSA9PSAxKSB7CiAgICBicmVhazsKICB9CiAgY291bnQrKzsKICBpZiAoYTEgJSAyID09IDApIHsKICAgIGExIC89IDI7CiAgfSBlbHNlIHsKICAgIGExID0gYTEgKiAzICsgMTsKICB9CiAgaWYgKGExID4gKmFtYXgpIHsKICAgICphbWF4ID0gYTE7CiAgfQp9CnJldHVybiBjb3VudDsKfQoKaW50IG1haW4oKQp7CmludCBpOwppbnQgYW1heDsKaW50IG1heGxlbjsKaW50IG1heGluaTsKaW50IGxlbjsKCm1heGxlbiA9IDA7Cm1heGluaSA9IDA7CmZvciAoaSA9IDI7IGkgPD0gMTAwMDAwOyBpKyspIHsKICBsZW4gPSBjb2xsYXR6KGksICZhbWF4KTsKICBpZiAobGVuID4gbWF4bGVuKSB7CiAgICBtYXhsZW4gPSBsZW47CiAgICBtYXhpbmkgPSBpOwogIH0KfQpwcmludGYoIiVkLCAlZFxuIiwgbWF4aW5pLCBtYXhsZW4pOwpyZXR1cm4gMDsKfQo=