(UVA)100-3n+1

#include <stdio.h>
int main(){

    unsigned long n, i, a, b, c, count, max;
    while (scanf("%ld%ld", &a, &b) == 2) {
      printf("%ld %ld", a, b);
      if (a > b)  {
            c = a;
            a = b;
            b = c;  }
       max = 0;
        for (i = a; i <= b; i++) {
            n = i;
            count = 1;
            while(n != 1)  {
               if (n % 2 == 0) n = n / 2;
        else n = 3 * n + 1;
                 cycle++;  }
            if(count>max) max=count;}
        printf(" %ld\n", max); }
    return 0;
}

留言

這個網誌中的熱門文章

Bundle Adjustment 光束平差法

Structure From Motion