title: Unable to determine why code stops after printing 113383
body: <p>I am trying to code the first problem from programming challenges books. The code calculates number of numbers generated from a to b.<br/> the new n is n/2 if n is even and if its odd, its 3*n+1<br/> For e.g. for 22 its will calculate numbers 22 11 34 17 52 26 13 40 20 10 5 16 8 4 2 1 and so the number of numbers is 16.The code stops after printing 113383, i gave input as <br/>1 1000000</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;map&gt;
  #include &lt;vector&gt;
  
  using std::cout;
  using std::cin;
  using std::string;
  using std::endl;
  
  
  using std::vector;
  using std::map;
  map&lt;long,long&gt; solution;
  
  
  long sequences(long n) {
  // returns the number of numbers(including 1) `n`produces till it becomes 1
      if(n==1)
          return 1;
      else{
          // assuming n&gt;1
  
          if(solution.find(n)!=solution.end())
              return solution.find(n)-&gt;second;
          long size = 0;
          while(n!=1){
              if(n%2==0){
                  n = n/2;
                  if(solution.find(n)!=solution.end())
                      return solution.find(n)-&gt;second + size;
  
              }
              else{
                  n = 3*n+1;
              }
              size++;
          }
          return size+1;
      }
  }
  long sequences(long a,long b){
      // returns the maximum numbers produced by numbers from a to b inclusive
      long result,max = -1;
      if(a&lt;b){
          for(long i=a;i&lt;=b;i=i+1){
              if(solution.find(i) == solution.end()){
                  cout&lt;&lt; i &lt;&lt; endl;
                  result = sequences(i);
                  solution.insert(map&lt;long,long&gt;::value_type(i,result));
  
              }
              else{
                  //i present in solution
                  result = solution.find(i)-&gt;second;
              }
              if(result&gt;max)
                  max = result;
          }
          return max;
      }
      return -1;
  }
  
  
  
  int main(int argc, char* argv[]) {
  
      long a,b,max;
  
  
      cin &gt;&gt; a &gt;&gt; b;
  //  while(cin&gt;&gt;a&gt;&gt;b){
          cout&lt;&lt;a&lt;&lt;" "&lt;&lt;b&lt;&lt;" "&lt;&lt;sequences(a,b)&lt;&lt;endl;
      /*}*/
  
      return 0;
  }
  </code></pre>