#include <stdio.h>
int collatz(int a1, int *amax)
{
while (a1 != 1) {
if (*amax < a1)*amax = a1;
a1 = (a1 % 2) ?
a1 * 3 + 1 :
a1 / 2;
return 1 + collatz(a1, amax);
}
return 1;
}
int main()
{
int i, amax, len;
int max_of_i, max_of_amax = 0, max_of_len = 0;
for (i = 2; i <= 100000; ++i) {
amax = 0;
len = collatz(i, &amax);
if (max_of_amax < amax) {
max_of_i = i;
max_of_amax = amax;
max_of_len = len;
}
// printf("%d %d %d\n", i, len, amax);
}
printf("%d %d %d\n", max_of_i
, max_of_len
, max_of_amax
); return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CmludCBjb2xsYXR6KGludCBhMSwgaW50ICphbWF4KQp7CiAgd2hpbGUgKGExICE9IDEpIHsKICAgIGlmICgqYW1heCA8IGExKSphbWF4ID0gYTE7CiAgICBhMSA9IChhMSAlIDIpID8KICAgICAgICAgYTEgKiAzICsgMSA6CiAgICAgICAgIGExIC8gMjsKICAgIHJldHVybiAxICsgY29sbGF0eihhMSwgYW1heCk7CiAgfQogIHJldHVybiAxOwp9CmludCBtYWluKCkKewogIGludCBpLCBhbWF4LCBsZW47CiAgaW50IG1heF9vZl9pLCBtYXhfb2ZfYW1heCA9IDAsIG1heF9vZl9sZW4gPSAwOwogIGZvciAoaSA9IDI7IGkgPD0gMTAwMDAwOyArK2kpIHsKICAgIGFtYXggPSAwOwogICAgbGVuID0gY29sbGF0eihpLCAmYW1heCk7CiAgICBpZiAobWF4X29mX2FtYXggPCBhbWF4KSB7CiAgICAgIG1heF9vZl9pID0gaTsKICAgICAgbWF4X29mX2FtYXggPSBhbWF4OwogICAgICBtYXhfb2ZfbGVuID0gbGVuOwogICAgfQogICAgLy8gcHJpbnRmKCIlZCAlZCAlZFxuIiwgaSwgbGVuLCBhbWF4KTsKICB9CiAgcHJpbnRmKCIlZCAlZCAlZFxuIiwgbWF4X29mX2ksIG1heF9vZl9sZW4sIG1heF9vZl9hbWF4KTsKICByZXR1cm4gMDsKfQo=