Why is this 3n+1 saying that my submission is wrong?
<p>I am trying to solve the famous 3m+1 problem. Using this source code, I don't know why I'm getting wrong answer :/  Although, if I run it , it works fine.</p>

<pre><code>#include &lt;iostream&gt;
using namespace std;
long int cycle(long int,long int);
int main()
{
    long int i=0, j=0;

    while (cin &gt;&gt; i &gt;&gt; j)
    {
        if(i &gt;= 0 &amp;&amp; j &gt;= 0 &amp;&amp; j&lt;= 1000000 &amp;&amp; i &lt;= 1000000)
        {
            cout &lt;&lt; i &lt;&lt; " " &lt;&lt; j &lt;&lt;  " " &lt;&lt;cycle(i,j) &lt;&lt; endl;
        }
    }
    return 0;
}

long int cycle(long int start,long int end)
{
    int largest_cycle = 0;
    int n =0;
    int counter =0;
    for(int j=start;j&lt;=end;j++)
    {
        n=j;
        counter =0;
        while(n != 1)
        {
            counter++;
            if( n % 2 == 0)
                n /=2;
            else 
                n = (3*n) +1;

            if( n==1)
                counter++;
        }
        if(counter &gt; largest_cycle)
            largest_cycle = counter;
    }
    return largest_cycle;
}
</code></pre>

<p>any help will be highly appreciated.</p>
