码迷,mamicode.com
首页 > 其他好文 > 详细

1293. 3n+1数链问题

时间:2016-10-22 15:04:41      阅读:139      评论:0      收藏:0      [点我收藏+]

标签:names   stream   ret   max   return   iostream   pac   ios   int   

#include<iostream>
using namespace std;
int main()
{
 int i,j;
 cin>>i>>j;
 int max=0;
 for(int t=i;t<=j;t++){
    int len=1;
    int a=t;
    len ++;
    while(a!=1){
      if(a%2==0){
       a=a/2;
      }
      else{
       a=3*a+1;
      }
      ++len;
    }
    if(len>max) max=len;
 }
 cout<<max<<endl;
 return 0;
}

1293. 3n+1数链问题

标签:names   stream   ret   max   return   iostream   pac   ios   int   

原文地址:http://www.cnblogs.com/sysu-eeman-yang/p/5987455.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!