标签:
#include<iostream> using namespace std; bool isOod(int num){ if(num%2==0){ return false; }else{ return true; } } int calCycleLength(int n){ int len=0; if(n==1){ return 1; }else{ if(isOod(n)){ n=3*n+1; len++; return len+calCycleLength(n); }else{ n/=2; len++; return len+calCycleLength(n); } } } int main(int argc, char *argv[]){ int input1, input2; int inputSmall, inputBig; int maxCycleLen; while(cin>>input1>>input2){ maxCycleLen=0; if(input1>input2){ inputSmall=input2; inputBig=input1; }else{ inputSmall=input1; inputBig=input2; } for(int i=inputSmall;i<=inputBig;i++){ int len=calCycleLength(i); if(len>maxCycleLen){ maxCycleLen=len; } } cout<<input1<<" "<<input2<<" "<<maxCycleLen<<endl; } return 0; }
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:
原文地址:http://blog.csdn.net/eddy_liu/article/details/46955967