# my frist ACM solve

problem 100

#include stdio.h

int calc (unsigned long int i, unsigned long int j, unsigned long int f);

int
main (void)
{
unsigned long int i, j, f;
while(scanf (“%lu”, &i)==1)
{
if (!(0 < i && i < 1000000))
{
scanf (“%lu”, &i);
}
scanf (“%lu”, &j);
if (!(0 < j && j < 1000000)) {
scanf (“%lu”, &j);
}
printf (“%lut %lut”, i, j);
if (i > j)
{
f = i – j;
f = f + 1;
}
else
{
f = j – i;
f = f + 1;
}
calc (i, j, f);
}
return 0;
}

int calc (unsigned long int i, unsigned long int j, unsigned long int f)

{
unsigned long int m, k = 1, n = 0;
unsigned long int l[f];
unsigned long int p;

if (i > j)
{
p = i – j;
p = p + 1;
for (; j 1;)
{
if (m % 2 == 0)
m = m / 2;
else
m = 3 * m + 1;
k = k + 1;
}
l[n] = k;
n = n + 1;
k = 1;
}
}
else
{
p = j – i;
p = p + 1;
for (; i 1;)
{
if (m % 2 == 0)
m = m / 2;
else
m = 3 * m + 1;
k = k + 1;
}
l[n] = k;
n = n + 1;
k = 1;
}
}
p = p-1;
for (n = 0; n < p; n++)
{
if (l[n] > l[n + 1])
{
l[n + 1] = l[n];
}
}
printf (“%lun”, l[p]);
}

1. daveprehiem26054914 says: