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;
}

目录
相关文章
uva 11991 - Easy Problem from Rujia Liu?
这个题目的意思是输入n个数,m组询问,每组询问包含两个整数k,v,意思是询问整数v第k次出现的位置。
39 0
UVa1531 - Problem Bee
UVa1531 - Problem Bee
49 0
UVa389 - Basically Speaking
UVa389 - Basically Speaking
36 0
uva101 The Blocks Problem
uva101 The Blocks Problem
53 0
|
机器学习/深度学习 自然语言处理
|
人工智能 Java 安全
HDU 1039 Easier Done Than Said?
Easier Done Than Said? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 12751    Accepted Subm...
801 0
|
数据挖掘
poj-1207 THE 3n+1 problem
Description Problems in Computer Science are often classified as belonging to a certain class of problems (e.
792 0