title: Maximum cycle length in 3n+1 conjecture
body: <p>I'm trying to submit my code at <a href="http://www.programming-challenges.com" rel="nofollow">http://www.programming-challenges.com</a> but I only get just wrong answer. I've tried the big input numbers like 1000000 to test and my code returns the answer. if anybody can help I'd be really grateful. Here's my code anyway:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  unsigned int max_cycle(unsigned int i, unsigned int j);
  unsigned int cycle_size(unsigned int m);
  void swap(unsigned int *m, unsigned int *n);
  
  int main(int argc, char *argv[]) {
     unsigned int a, b;
     int scan;
  
     scan = scanf("%u %u", &amp;a, &amp;b);
     printf("%u %u %u", a, b, max_cycle(a, b));
     while (scan&gt; 0) {
         if((scan = scanf("%u %u", &amp;a, &amp;b)) &gt; 0) {
             printf("\n%u %u %u", a, b, max_cycle(a, b));
         }
     }
  
     return 0;
  }
  
  unsigned int max_cycle(unsigned int x, unsigned int y) {
      unsigned int length = 0;
      unsigned int max = 0;
  
      if(x &gt; y) {
          swap(&amp;x, &amp;y);
      }
  
      x++;
      while(x &lt; y) {
          length = cycle_size(x);
  
          if(length &gt; max) {
              max = length;
          }
  
          x++;
      }
  
      return max;
  }
  
  unsigned int cycle_size(unsigned int x) {
      unsigned int cntr = 1;
  
      while(x != 1) {
          if(x % 2 == 0) {
              x = x/2;
          } else {
              x = 3*x+1;
          }
  
          cntr++;
      }
  
      return cntr;    
  }
  
  void swap(unsigned int *x, unsigned int *y) {
      unsigned int term = 0;
  
      term = *x;
      *x = *y;
      *y = term;
  }
  </code></pre>