WLJ


私信TA

用户名:hputermux

访问量:14382

签 名:

等  级
排  名 593
经  验 4079
参赛次数 4
文章发表 43
年  龄 20
在职情况 学生
学  校 河南理工大学
专  业 计算机专业

  自我简介:

计算机科学与技术专业

解题思路:求最大循环长度

注意事项:

参考代码:

#include <iostream>

#include <cstdio>

using namespace std;

int main()

{

int m,n;

while(scanf("%d %d",&m,&n)!=EOF)

{

int ans = 0;

printf("%d %d",m,n);

if(m>n) swap(m,n);

for(int i=m;i<=n;i++)

{

int count = 1,k=i;

while(k!=1)

{

count++;

if(k&1)

{

k=3*k+1;

}

else

{

k=k/2;

}

}

if(count>ans)

{

ans = count;

}

}

printf(" %d\n",ans);

}

return 0;

}


 

0.0分

0 人评分

  评论区