BUT when I did that I get another problem.
When I check "My Submissions" it says "running" and after a while it writes : "Submission Error"
This is the modified code :
Code: Select all
//All input integers will be less than 1,000,000 and greater than 0 .
//There will be 2 inputs , i and j , for all integers from i to j we should get the Cycle-Length of '3n + 1' formula and return the maximum .
#include <iostream>
using std :: cout ;
using std :: cin ;
using std :: endl ;
int main ()
{
int i , j , CL = 1 , maxCL , tmp ; //CL is the Cycle-Length of the current number and maxCL is the maximum Cycle-Length and tmp is the temporary number which the operation will be done on .
cin >> i >> j ;
while (i > 0 && j > 0)
{
cout << i << " " << j << " " ; //We do not use an extra variable for numbers between i and j , we use the i itself in the for loop , so we'll lose the i at the end of the program .
if (i > j)
{
int swapij ;
swapij = i ;
i = j ;
j = swapij ;
}
maxCL = 0 ;
for ( ; i <= j ; i ++)
{
tmp = i ;
while (tmp > 1)
if (tmp %2 == 0)
{
tmp /= 2 ;
CL ++ ;
}
else
{
tmp = tmp * 3 + 1 ;
CL ++ ;
}
if (CL > maxCL)
maxCL = CL ;
CL = 1 ;
}
cout << maxCL << endl ;
cin >> i >> j ;
}
return 0 ;
}