title: The 3n+1 solution overflows in C++ VS2010
body: <p>I'm trying to solve the 3n+1 problem using VS2010 c++,in small inputs it works well,but when it reaches 113383 it overflows.</p>
  
  <p>Here is the <a href="http://acm.uva.es/p/v1/100.html" rel="nofollow" title="problem link">problem link</a>.</p>
  
  <p>This is the code I'm using to solve this problem :</p>
  
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  int main(void) {
      while (!cin.eof()) {
          int i, j, maxCycle = 0, tmaxCycle = 0;
          cin &gt;&gt; i &gt;&gt; j;
          for (int x = i; x &lt;= j; x++) {
              int n = x;
              tmaxCycle = 0;
              while (n != 1) {
                  if ((float)(n/2) != (n/2.0)) {
                      n = 3*n + 1;
                  }
                  else {
                      n /= 2;
                  }
                  tmaxCycle += 1;
                  if (n &lt; 0) {
                      int blah = 0; //just for the breakpoint
                  } 
              }
              tmaxCycle += 1;
              if (tmaxCycle &gt; maxCycle) {
                  maxCycle = tmaxCycle;
              }
          }
          cout &lt;&lt; i &lt;&lt; "\t" &lt;&lt; j &lt;&lt; "\t" &lt;&lt; maxCycle &lt;&lt; endl;
      }
      system("pause");
  }
  </code></pre>
  
  <p>I made a breakpoint  at line 15,and in this point values overflows</p>
  
  <pre><code>n=-1812855948 
  </code></pre>