开发者社区> JKXQJ> 正文

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;
+关注继续查看
题目链接:
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;
}

版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。

相关文章
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
立即下载
低代码开发师(初级)实战教程
立即下载
阿里巴巴DevOps 最佳实践手册
立即下载