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

JKXQJ
+关注
目录
打赏
0
0
0
0
25
分享
相关文章
uva 11991 - Easy Problem from Rujia Liu?
这个题目的意思是输入n个数,m组询问,每组询问包含两个整数k,v,意思是询问整数v第k次出现的位置。
53 0
UVa1531 - Problem Bee
UVa1531 - Problem Bee
66 0
uva101 The Blocks Problem
uva101 The Blocks Problem
70 0
UVa12478 - Hardest Problem Ever (枚举)
UVa12478 - Hardest Problem Ever (枚举)
58 0
数论 - SGU 107 987654321 problem
 987654321 problem Problem's Link   Mean:  略 analyse: 这道题目是道简单题.
794 0
【转】UVa Problem 100 The 3n+1 problem (3n+1 问题)——(离线计算)
1 // The 3n+1 problem (3n+1 问题) 2 // PC/UVa IDs: 110101/100, Popularity: A, Success rate: low Level: 1 3 // Verdict: Accepted 4 // Submission Date: 2011-05-22 5 // UVa Run Time: 0.032s 6 // 7 // 版权所有(C)2011,邱秋。
1114 0
uva 11991 Easy Problem from Rujia Liu?
点击打开链接uva 11991 思路: STL 分析: 1 题目要求的是第k个v的下标 2 题目的规模是10^6如果用暴力的话那么超时是肯定的,所以这里应该考虑用vector数组,每一个值作为一个vector,,然后把这个值出现在第几个位...
858 0
uva 1326 - Jurassic Remains
点击打开链接uva 1326 题意:给定n个由大写字母组成的字符串,选择尽量多的串使得每个大写字母都能出现偶数次 分析: 1 在一个字符串中每个字符出现的次数是无关的,重要的是只是这些次数的奇偶性。
943 0
AI助理

你好,我是AI助理

可以解答问题、推荐解决方案等