# uva 100 The 3n+1 problem

+关注继续查看
题目链接：
http://www.programming-challenges.com/pg.php?page=studenthome
/*
The 3n+1 problem
计算每个数的循环节长度，求给定区间的循环节长度的最大值。
*/
#include<iostream>
#include<stdio.h>
using namespace std;
int jk(int n)
{
int num=1;
while(n!=1)
{
if(n&1)
n+=(n<<1)+1;
else
n=n>>1;
num++;
}
return num;
}
int main()
{
int x,y,i;
// freopen("./pcio/110101.inp","r",stdin);
while(scanf("%d %d",&x,&y)!=EOF)
{
int xx=x,yy=y;
if(x>y)
swap(x,y);
int max=0;
for(i=x; i<=y; i++)
{
if(jk(i)>max)
max=jk(i);
}
printf("%d %d %d\n",xx,yy,max);
}
return 0;
}

HDU1002A + B Problem II
HDU1002A + B Problem II
23 0
UVA101---UVA101 The Blocks Problem
UVA101---UVA101 The Blocks Problem
21 0
【HDU 5572 An Easy Physics Problem】计算几何基础
2015上海区域赛现场赛第5题。 题目连接：http://acm.hdu.edu.cn/showproblem.php?pid=5572 题意：在平面上，已知圆(O, R)，点B、A（均在圆外），向量V。
924 0
poj-1207 THE 3n+1 problem
Description Problems in Computer Science are often classified as belonging to a certain class of problems (e.
736 0
+关注
JKXQJ

Problem Solving Recipes Learne