I'm trying to figure out, why this is always giving me a WA:
Code: Select all
#include <iostream>
using namespace std;
int main()
{
long i, j, n;
while (cin >> i >> j)
{
long hi, hj;
long max = 0;
if (i > j)
{
hi = j;
hj = i;
}
else
{
hi = i;
hj = j;
}
cout << i << " " << j << " ";
for (int t=hi;t<hj;t=t+1)
{
long c = 1;
n = t;
while (n != 1)
{
if ( (n % 2) != 0)
{
n = (3 * n) + 1;
}
else
{
(n = n / 2);
}
c = c + 1;
if (c > max)
{
max = c;
}
}
}
cout << max << endl;
}
}