I posted this problem again several hours ago and got SIGSEGV, but i DID NOT change my code!!!
Code: Select all
#include <stdio.h>
#include <string.h>
long sol[10001];
void precount()
{
long t;
long c;
for (long i = 1; i <= 10000; i++)
{
c = 0;
t = i;
while (t != 1)
{
if (t % 2) t = 3 * t + 1; else t /= 2;
c++;
}
sol[i] = c;
}
}
int main()
{
int n, m, p, q;
long max = 0;
precount();
while (scanf("%d %d", &n, &m) == 2)
{
max = 0;
if (m>n)
{
p = n;
q = m;
}
else
{
p = m;
q = n;
}
for (int i = p; i <= q; i++)
if (sol[i] > max) max = sol[i];
printf("%d %d %ld\n", n, m, ++max);
}
return 0;
}