#include <stdio.h> int CL(int k) { int tmp=k; int cnt=1; while(tmp!=1&&tmp>0) { if(tmp%2==0) { tmp=tmp/2; cnt++; } else { tmp=3*tmp+1; cnt++; } } return cnt; } int main() { int i,j,k; int got; int mcl;//maximum cycle length while(scanf("%d %d",&i,&j)==2) { if(!(i>0&&i<1e6&&j>0&&j<1e6)) break; printf("%d %d ",i,j); if(i>j) { i=i^j; j=i^j; i=i^j; } mcl=-1; for(k=i;k<=j;k++) { got=CL(k); if(got>mcl) mcl=got; } printf("%d\n",mcl); } return 0; }
0.0分
0 人评分
C语言程序设计教程(第三版)课后习题6.1 (C语言代码)浏览:668 |
多输入输出练习1 (C语言代码)浏览:1187 |
printf基础练习2 (C语言代码)浏览:305 |
简单的a+b (C语言代码)浏览:340 |
C语言程序设计教程(第三版)课后习题5.4 (C语言代码)浏览:1311 |
WU-蓝桥杯算法提高VIP-交换Easy (C++代码)浏览:1118 |
本人酷爱递归实现很多问题,这里也是浏览:556 |
WU-输入输出格式练习 (C++代码)浏览:1082 |
【矩阵】 (C++代码)浏览:949 |
蛇行矩阵 (C语言代码)浏览:505 |