C++ Collatz Conjecture Optimization
<p>In ProjectEuler problem #14, one needs to find the longest Collatz chain, up to 1 million. I found a halfway decent way to do so, however, it feels like I'm just being stupid because I can't find a way to make this code more efficient (the code is supposed to only print out the solution, after it tests 1 to 1 million, but hasn't printed anyting out after 10 minutes). Am I tackling this problem the wrong way, or is there a way to optimize my existing code?</p>

<pre><code>#include &lt;iostream&gt;
using namespace std;

int main()
{
    int i;
    int x;
    int n;
    int superN;
    int superI;

    superN = 0;
    superI = 0;

    for (i = 1; i &lt;= 1000000; i++) {
        x = i;
        n = 1;

        do {
            if (x % 2 == 0) {
                x = x / 2;
            }

            if (x % 2 == 1 &amp;&amp; x != 1) {
                x = 3 * x + 1;
            }

            n++;

            if (n &gt; superN) {
                superN = n;
                superI = i;
            }
        } while (x != 1);
    }

    cout &lt;&lt; "The number " &lt;&lt; superI &lt;&lt; " ran for " &lt;&lt; superN &lt;&lt; " terms.";
    system("pause");
    return 0;
}
</code></pre>