題目(連結)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
#include <stdlib.h> #include <stdio.h> int func_cycle_length(int n); int main(){ int i,j,max,start,end; while(scanf("%d %d",&i,&j) != EOF){ max = 0; if(i < j){ start = i; end = j; }else{ start = j; end = i; } while(start <= end){ int t_count = func_cycle_length(start++); if(t_count > max) max = t_count; } printf("%d %d %d\n",i,j,max); } return 0; } int func_cycle_length(int n){ int count = 1; while(n!=1){ if(n%2!=0) n = 3 * n + 1; else n /= 2; count++; } return count; } |
文章標籤
全站熱搜