Why does changing int to long speed up the execution? : <p>I was trying to solve <a href="https://projecteuler.net/problem=14" rel="noreferrer">problem #14 from Project Euler</a>, and had written the following C#...</p>

<pre><code>int maxColl = 0;
int maxLen = 0;
for (int i = 2; i &lt; 1000000; i++) {
  int coll = i;
  int len = 1;
  while (coll != 1) {
    if (coll % 2 == 0) {
      coll = coll / 2;
    } else {
      coll = 3 * coll + 1;
    }
    len++;
  }
  if (len &gt; maxLen) {
    maxLen = len;
    maxColl = i;
  }
}
</code></pre>

<p>Trouble was, it just ran and ran without seeming to stop.</p>

<p>After searching for other people's solution to the problem, I saw one looking very similar, except that he had used long instead of int. I didn't see why this should be necessary, as all of the numbers involved in this problem are well within the range of an int, but I tried it anyway.</p>

<p>Changing int to long made the code run in just over 2 seconds.</p>

<p>Anyone able to explain this to me?</p>
